-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (58 loc) · 1.65 KB
/
index.js
File metadata and controls
66 lines (58 loc) · 1.65 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Module dependencies.
*/
const express = require('express');
const Stackable = require('stackable');
const errorHandler = require('errorhandler');
const hbs = require('hbs');
const path = require('path');
const bodyParser = require('body-parser');
const expressStatusMonitor = require('express-status-monitor');
const expressValidator = require('express-validator');
/**
* Create Express server.
*/
const app = express();
hbs.registerPartials(path.join(__dirname, 'views/partials'));
app.set('port', process.env.PORT || 5000);
app.use(express.static(`${__dirname}/public`));
app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, 'views'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());
app.use(expressStatusMonitor());
app.use(errorHandler());
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
/**
* Configs.
*/
const config = require('./config/main');
/**
* Intialize stackable.
*/
app.use((req, res, next) => {
res.stackable = new Stackable(config.stackblePrivateKey);
next();
});
/**
* Controllers (route handlers).
*/
const mainController = require('./controllers/main');
const postController = require('./controllers/post');
/**
* Primary app routes.
*/
app.get('/', mainController.index);
app.get('/post/:id', postController.view);
/**
* Start Express server.
*/
app.listen(app.get('port'), () => {
console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env'));
});
module.exports = app;