mirror of
https://github.com/microsoft/TypeScript-Node-Starter.git
synced 2026-03-23 06:41:20 +00:00
have env var scripts.. but I'm not sure I like it
This commit is contained in:
12
src/app.ts
12
src/app.ts
@@ -12,19 +12,19 @@ import * as mongoose from "mongoose";
|
||||
import * as passport from "passport";
|
||||
import * as expressValidator from "express-validator";
|
||||
import * as bluebird from "bluebird";
|
||||
import { MONGODB_URI, SESSION_SECRET } from "./util/loadSecrets";
|
||||
|
||||
console.log(MONGODB_URI);
|
||||
console.log(SESSION_SECRET);
|
||||
|
||||
const MongoStore = mongo(session);
|
||||
|
||||
// Load environment variables from .env file, where API keys and passwords are configured
|
||||
dotenv.config({ path: ".env.example" });
|
||||
|
||||
// Controllers (route handlers)
|
||||
import * as homeController from "./controllers/home";
|
||||
import * as userController from "./controllers/user";
|
||||
import * as apiController from "./controllers/api";
|
||||
import * as contactController from "./controllers/contact";
|
||||
|
||||
|
||||
// API keys and Passport configuration
|
||||
import * as passportConfig from "./config/passport";
|
||||
|
||||
@@ -32,7 +32,7 @@ import * as passportConfig from "./config/passport";
|
||||
const app = express();
|
||||
|
||||
// Connect to MongoDB
|
||||
const mongoUrl = process.env.MONGOLAB_URI;
|
||||
const mongoUrl = MONGODB_URI;
|
||||
(<any>mongoose).Promise = bluebird;
|
||||
mongoose.connect(mongoUrl, {useMongoClient: true}).then(
|
||||
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
|
||||
@@ -53,7 +53,7 @@ app.use(expressValidator());
|
||||
app.use(session({
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
secret: process.env.SESSION_SECRET,
|
||||
secret: SESSION_SECRET,
|
||||
store: new MongoStore({
|
||||
url: mongoUrl,
|
||||
autoReconnect: true
|
||||
|
||||
34
src/util/loadSecrets.ts
Normal file
34
src/util/loadSecrets.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// import log from './logger'; TODO
|
||||
|
||||
export const ENVIRONMENT = process.env.NODE_ENV;
|
||||
const prod = ENVIRONMENT === "production";
|
||||
|
||||
export const SESSION_SECRET = process.env["SESSION_SECRET"];
|
||||
export const MONGODB_URI = prod ? process.env["MONGODB_URI"] : process.env["MONGODB_URI_LOCAL"];
|
||||
|
||||
|
||||
|
||||
// if (!GITHUB_CLIENT_SECRET) {
|
||||
// log.fatal("ERROR\tNo client secret. Set TCQ_GH_SECRET.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!GITHUB_CLIENT_ID) {
|
||||
// log.fatal("ERROR\tNo client id. Set TCQ_GH_ID.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!SESSION_SECRET) {
|
||||
// log.fatal("ERROR\tNo session secret. Set TCQ_SESSION_SECRET.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!CDB_SECRET) {
|
||||
// log.fatal("ERROR\tNo CosmosDB secret. Set TCQ_CDB_SECRET.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
// if (!AI_IKEY) {
|
||||
// log.fatal("ERROR\tNo Application Insights Instrumentation Key. Set TCQ_AI_IKEY.");
|
||||
// process.exit(1);
|
||||
// }
|
||||
Reference in New Issue
Block a user