-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.js
100 lines (80 loc) · 3.18 KB
/
server.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
(function(){
// DEPENDENCIES ===================================
var express = require("express");
var bodyParser = require("body-parser");
var exphbs = require("express-handlebars");
var path = require("path");
var methodOverride = require("method-override");
require('dotenv').config();
var multer = require('multer');
// CONFIG =========================================
var app = express();
var port = process.env.PORT || 3000;
app.disable("x-powered-by");
// Set Static Directory
app.use(express.static(path.join(__dirname, "public")));
// Set Handlebars
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Set Body Parser
app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: 'application/vnd.api+json'}));
// app.use(bodyParser.urlencoded({extended: false,limit: '50mb'}));
// Override with POST having ?_method=
app.use(methodOverride("_method"));
// logs each url that is requested, then passes it on.
app.use(function(req, res, next) {
console.log("url : " + req.url);
next();
});
// ROUTES =========================================
// Temporary route to confirm ownership with LetsEncrypt. Will be removed after confirmation
// app.get('/.well-known/acme-challenge/ffilB30ecS6Z3LRkkcTWeBbL6Yu_RlyyVOjt8C3hoOs',function(req,res){
// // res.sendFile('public/ssl-cert-file');
// res.sendFile('ssl-cert-file', { root: path.join(__dirname, '/public') });
// })
// api has to be before routes or else everything would
// would hit routes (including api routes)
var api = require('./controllers/api_controller.js');
app.use('/', api);
var routes = require("./controllers/model_controller.js");
app.use("/", routes);
var faceRoutes = require("./controllers/face_controller.js");
app.use("/", faceRoutes);
var picRoutes = require("./controllers/picture_controller.js");
app.use("/", picRoutes);
var voiceRoutes = require("./controllers/voice_controller.js");
app.use("/", voiceRoutes);
var email = require("./controllers/email_controller.js");
app.use("/", email);
// var speech = require("./controllers/polly_controller.js");
// app.use("/", speech);
// ERRORS =========================================
app.use(function(req, res) {
// res.type("text/html");
res.status(404);
res.render("404");
});
app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500);
res.render("500");
});
//SEQUELIZE INITIALIZATION FOR DATABASE
var db = require("./models");
db.sequelize.sync({ force: true }).then(function() {
app.listen(port, function() {
console.log("App listening on PORT " + port);
console.log(`-------------------------------------------------------
ready @ ${port}`);
});
});
// START SERVER ===================================
// db.sequelize.sync({force: true}) .then(function(){
// })
//==================================================
})();