Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

made some changes to mongo connection #63

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,5 @@ MONGOLAB_URI=mongodb://localhost:27017

SESSION_SECRET=ashdfjhasdlkjfhalksdjhflak

MAILGUN_USER=postmaster@sandbox697fcddc09814c6b83718b9fd5d4e5dc.mailgun.org
MAILGUN_PASSWORD=29eldds1uri6

SENDGRID_USER=hslogin
SENDGRID_PASSWORD=hspassword00

FACEBOOK_ID=754220301289665
FACEBOOK_SECRET=41860e58c256a3d7ad8267d3c1939a4a

INSTAGRAM_ID=9f5c39ab236a48e0aec354acb77eee9b
INSTAGRAM_SECRET=5920619aafe842128673e793a1c40028

GITHUB_ID=cb448b1d4f0c743a1e36
GITHUB_SECRET=815aa4606f476444691c5f1c16b9c70da6714dc6

TWITTER_KEY=6NNBDyJ2TavL407A3lWxPFKBI
TWITTER_SECRET=ZHaYyK3DQCqv49Z9ofsYdqiUgeoICyh6uoBgFfu7OeYC7wTQKa

GOOGLE_ID=828110519058.apps.googleusercontent.com
GOOGLE_SECRET=JdZsIaWhUFIchmC1a_IZzOHb

TWILIO_SID=AC6f0edc4c47becc6d0a952536fc9a6025
TWILIO_TOKEN=a67170ff7afa2df3f4c7d97cd240d0f3

FACEBOOK_SECRET=41860e58c256a3d7ad8267d3c1939a4a
41 changes: 29 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
"author": "Bowden Kelly",
"license": "MIT",
"scripts": {
"start": "npm run build && npm run watch",
"start": "npm run serve",
"build": "npm run build-sass && npm run build-ts && npm run tslint && npm run copy-static-assets",
"serve": "nodemon dist/server.js",
"watch": "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\"",
"serve": "node dist/server.js",
"watch-node": "nodemon dist/server.js",
"watch": "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 watch-node\"",
"test": "jest --forceExit",
"build-ts": "tsc",
"watch-ts": "tsc -w",
"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": "node copyStaticAssets.js",
"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": "node copyStaticAssets.js"
},
"jest": {
"globals": {
Expand All @@ -45,6 +43,7 @@
"dependencies": {
"async": "^2.5.0",
"bcrypt-nodejs": "^0.0.3",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"compression": "^1.7.1",
"connect-mongo": "^1.3.2",
Expand All @@ -57,7 +56,7 @@
"fbgraph": "^1.4.1",
"lodash": "^4.17.4",
"lusca": "^1.5.2",
"mongoose": "^4.12.4",
"mongoose": "^4.13.7",
"morgan": "^1.9.0",
"nodemailer": "^2.7.2",
"passport": "^0.4.0",
Expand All @@ -69,6 +68,7 @@
"devDependencies": {
"@types/async": "^2.0.40",
"@types/bcrypt-nodejs": "0.0.30",
"@types/bluebird": "^3.5.18",
"@types/body-parser": "^1.16.2",
"@types/compression": "0.0.33",
"@types/connect-mongo": "0.0.34",
Expand Down
59 changes: 22 additions & 37 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* Module dependencies.
*/
import * as express from "express";
import * as compression from "compression"; // compresses requests
import * as session from "express-session";
Expand All @@ -13,50 +10,38 @@ import * as flash from "express-flash";
import * as path from "path";
import * as mongoose from "mongoose";
import * as passport from "passport";
import expressValidator = require("express-validator");
import * as expressValidator from "express-validator";
import * as bluebird from "bluebird";

const MongoStore = mongo(session);

/**
* Load environment variables from .env file, where API keys and passwords are configured.
*/
// Load environment variables from .env file, where API keys and passwords are configured
dotenv.config({ path: ".env.example" });


/**
* Controllers (route handlers).
*/
// 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.
*/

// API keys and Passport configuration
import * as passportConfig from "./config/passport";

/**
* Create Express server.
*/
// Create Express server
const app = express();

/**
* Connect to MongoDB.
*/
// mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);

mongoose.connection.on("error", () => {
console.log("MongoDB connection error. Please make sure MongoDB is running.");
process.exit();
// Connect to MongoDB
const mongoUrl = process.env.MONGOLAB_URI;
(<any>mongoose).Promise = bluebird;
mongoose.connect(mongoUrl, {useMongoClient: true}).then(
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
).catch(err => {
console.log("MongoDB connection error. Please make sure MongoDB is running. " + err);
// process.exit();
});



/**
* Express configuration.
*/
// Express configuration
app.set("port", process.env.PORT || 3000);
app.set("views", path.join(__dirname, "../views"));
app.set("view engine", "pug");
Expand All @@ -70,7 +55,7 @@ app.use(session({
saveUninitialized: true,
secret: process.env.SESSION_SECRET,
store: new MongoStore({
url: process.env.MONGODB_URI || process.env.MONGOLAB_URI,
url: mongoUrl,
autoReconnect: true
})
}));
Expand All @@ -86,13 +71,13 @@ app.use((req, res, next) => {
app.use((req, res, next) => {
// After successful login, redirect back to the intended page
if (!req.user &&
req.path !== "/login" &&
req.path !== "/signup" &&
!req.path.match(/^\/auth/) &&
!req.path.match(/\./)) {
req.path !== "/login" &&
req.path !== "/signup" &&
!req.path.match(/^\/auth/) &&
!req.path.match(/\./)) {
req.session.returnTo = req.path;
} else if (req.user &&
req.path == "/account") {
req.path == "/account") {
req.session.returnTo = req.path;
}
next();
Expand Down