UNPKG

2.15 kBJavaScriptView Raw
1var express = require('express'),
2 expressSession = require('express-session'),
3// dotenv = require('dotenv').config(),
4 mongoose = require('mongoose'),
5 bodyParser = require('body-parser'),
6 path = require('path'),
7 passport = require('passport')
8
9//var app = express()
10//const port = process.env.PORT || 3000
11
12require('./models/user') //load the User model
13//Bring in the Passport config after model is defined
14require('./config/passport')
15
16exports.launch = function(app) {
17 //Passport configuration/initialization
18 app.use(expressSession({
19 secret: process.env.SESSION_SECRET,
20 saveUninitialized: true,
21 resave: true
22 }))
23 app.use(passport.initialize())
24 app.use(passport.session())
25
26 //Connect to mongodb using mongoose
27 var db = mongoose.connect(process.env.DB, {useMongoClient: true})
28 db.on('error', console.error.bind(console, 'connection error:'))
29 db.once('open', function () {
30 console.log('Connection to the db is opened')
31 })
32
33 //Call routes
34 var routes = require('./routes/router')
35 app.use('/api', routes)
36
37 // Create link to Angular build directory
38 // var distDir = __dirname + "/../../dist/" //IMPORTANT: __dirname will be node_modules/ctrlb-prod-fw. So need to go back 2 folders to locate dist directory where client angular application will exist
39 // app.use(express.static(distDir))
40 // app.use(express.static(path.join(__dirname, 'public')))
41
42 app.use(bodyParser.urlencoded({
43 extended: true
44 }))
45 app.use(bodyParser.json())
46 //app.use(cors()) //check without this
47
48 //No need of this get route as product framework will be used for api calls only
49 // app.get("/", function(req, res) {
50 // res.status(200).sendFile(distDir + 'index.html')
51 // })
52}
53
54//Not required, coded just for test. This project is for providing api library for most common application functions
55// exports.launch = function() {
56// app.listen(port, function(req, res) {
57// console.log('Listening on port ' + port)
58// })
59// }
60
61// app.listen(port, function(req, res) {
62// console.log('Listening on port ' + port)
63// })