-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (35 loc) · 1.21 KB
/
Copy pathapp.js
File metadata and controls
43 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require('dotenv').config();
const bodyParser = require('body-parser');
const chalk = require('chalk');
const express = require('express'),
app = express();
const mongoose = require('mongoose');
const morgan = require('morgan');
const session = require('express-session'),
MongoStore = require('connect-mongo')(session);
const router = require('./server/routes');
// TODO: put as env variable
mongoose.connect('mongodb://localhost:27017/fstemplate');
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
app.use(session({
maxAge: 1000 * 60 * 60 * 24 * 7,
resave: true,
saveUnitialized: false,
// TODO: put this in the env
secret: 'TODO: make this an env var',
store: new MongoStore({
mongooseConnection: db
})
}));
// middleware
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// TODO: Outside of webpack-dev-server, index is looking for assets in the wrong place. Where SHOULD we put assets?
app.use(express.static('browser/assets'));
app.use('/', router);
app.listen(process.env.PORT || 3000, function() {
console.log(chalk.green(`App is listening on port ${this.address().port}`));
});
module.exports = app;