-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (34 loc) · 1.18 KB
/
app.js
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
const express = require('express');
const app = express();
// Setup session cookie with custom signature
const cookieSession = require('cookie-session')
const Keygrip = require('keygrip')
app.use(cookieSession({
name: 'session',
keys: new Keygrip(['key1', 'key2'], 'SHA384', 'base64'),
// Cookie Options
maxAge: 60 * 1000 // Session expires after 1 minute of inactivity
}))
// Deploy site at root
app.use(express.static('public'));
// Logging Middleware
const morgan = require('morgan')
app.use(morgan('dev'));
// Import and mount the expressionsRouter
const expressionsRouter = require('./api/v1/expressions.js');
app.use('/expressions', expressionsRouter);
// Import and mount the helloRouter with cors enabled
const helloRouter = require('./api/v1/hello.js');
const cors = require('cors');
app.use('/hello', cors(), helloRouter);
// Import and mount the usersRouter
const usersRouter = require('./api/v1/users.js');
app.use('/users', usersRouter);
// Error handling middleware
const errorhandler = require('errorhandler')
app.use(errorhandler())
// Deploy application server
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`Server is listening on ${PORT}`);
});