Last active
January 4, 2016 00:51
-
-
Save miyamotodev123/6d43d1c97f71162e6a3f to your computer and use it in GitHub Desktop.
auth set up and testing server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get all the tools we need | |
var express = require('express'); | |
var app = express(); | |
var port = process.env.PORT || 8080; | |
var mongoose = require('mongoose'); | |
var passport = require('passport'); | |
var morgan = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
var session = require('express-session'); | |
var configDB = require('./config/database.js'); | |
// configuration =============================================================== | |
mongoose.connect(configDB.url); // connect to our database | |
require('./config/passport')(passport); // pass passport for configuration | |
// set up our express application | |
app.use(morgan('dev')); // log every request to the console | |
app.use(cookieParser()); // read cookies (needed for auth) | |
app.use(bodyParser.json()); // get information from html forms | |
app.use(bodyParser.urlencoded({ extended: true })); | |
// required for passport | |
app.use(session({ secret: 'session-secret' })); // session secret | |
app.use(passport.initialize()); | |
app.use(passport.session()); // persistent login sessions | |
// routes ====================================================================== | |
require('./app/routes.js')(app, passport); // load our routes and pass in our app and fully configured passport | |
// launch ====================================================================== | |
app.listen(port); | |
console.log('Server listening on port: ' + port); | |
// export the app object and make it available to other files such as the test file | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment