-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (52 loc) · 1.67 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const http = require('http');
const express = require('express');
const app = express();
const server = http.createServer(app);
const dbconnection = require('./connection.js');
const hackdoController = require('./controllers/hackdo.js');
const HomepageController = require('./controllers/homepage.js');
const FileServeController = require('./controllers/fileserve.js');
const HackdoModel = require('./model/hackdo.js');
const dispatchModel = require('./utils.js').dispatchModel;
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
app.use(express.static('./public'));
var hbs = exphbs.create({
defaultLayout: 'main',
extname: '.hbs'
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use("*",(req, res, next)=> {
res.dispatchModel = dispatchModel;
next();
});
dbconnection(app, function(err, connection) {
if(err) throw err;
console.log("connection open")
let h4ckdo = HackdoModel(connection);
new hackdoController(app, h4ckdo, connection);
new FileServeController(app, h4ckdo, connection);
new HomepageController(app, h4ckdo, connection);
if(process.env.STAGING) {
const newman = require('newman');
newman.run({
collection: require('./Hackdoodles.postman_collection.json'),
reporters: 'cli',
bail: true
}, function (err) {
if (err) {
throw err;
process.exit(1);
} else {
console.log('collection run complete!');
process.exit(0);
}
});
}
})
server.listen(process.env.PORT || 3000,()=> console.log("listen at: 3000"));