mirror of
https://github.com/microsoft/TypeScript-Node-Starter.git
synced 2026-03-22 06:57:19 +00:00
have env var scripts.. but I'm not sure I like it
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -33,3 +33,10 @@ Thumbs.db
|
||||
|
||||
# Ignore built ts files
|
||||
dist/**/*
|
||||
|
||||
# Ignore scripts that contains secrets
|
||||
env.sh
|
||||
env.cmd
|
||||
|
||||
# coverage reports
|
||||
coverage/**/*
|
||||
@@ -20,10 +20,7 @@
|
||||
"build-sass": "node-sass src/public/css/main.scss dist/public/css/main.css",
|
||||
"watch-sass": "node-sass -w src/public/css/main.scss dist/public/css/main.css",
|
||||
"tslint": "tslint -c tslint.json -p tsconfig.json",
|
||||
"copy-static-assets": "ts-node copyStaticAssets.ts",
|
||||
"debug": "npm run build && npm run watch-debug",
|
||||
"serve-debug": "nodemon --inspect dist/server.js",
|
||||
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\""
|
||||
"copy-static-assets": "ts-node copyStaticAssets.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.6.0",
|
||||
|
||||
11
sample.cmd
Normal file
11
sample.cmd
Normal file
@@ -0,0 +1,11 @@
|
||||
:: Note we depend on NODE_ENV being set to dictate which of the env variables below get loaded at runtime.
|
||||
:: See README for more details
|
||||
|
||||
:: Database connection strings below. You'll eventually have a lot of these!
|
||||
:: Get this from https://mlab.com/home after you've logged in and created a database
|
||||
set MONGODB_URI=mongodb://<mlab_user>:<mlab_password>@<mlab_connection_url>
|
||||
:: This is standard if you have mongodb running locally and you didn't change default ports
|
||||
set MONGODB_URI_LOCAL=mongodb://localhost:27017
|
||||
|
||||
:: Put lots of randomness in this
|
||||
set SESSION_SECRET=ashdfjhasdlkjfhalksdjhflak
|
||||
12
sample.sh
Executable file
12
sample.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
# Note we depend on NODE_ENV being set to dictate which of the env variables below get loaded at runtime.
|
||||
# See README for more details
|
||||
|
||||
# Database connection strings below. You'll eventually have a lot of these!
|
||||
# Get this from https://mlab.com/home after you've logged in and created a database
|
||||
export MONGODB_URI="mongodb://<mlab_user>:<mlab_password>@<mlab_connection_url>"
|
||||
# This is standard if you have mongodb running locally and you didn't change default ports
|
||||
export MONGODB_URI_DEV="mongodb://localhost:27017"
|
||||
|
||||
# Put lots of randomness in these
|
||||
export SESSION_SECRET="ashdfjhasdlkjfhalksdjhflak"
|
||||
export SESSION_SECRET_DEV="ashdfjhasdlkjfhalksdjhflak"
|
||||
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