-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
66 lines (52 loc) · 1.85 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
65
66
/*
* App file for Express.js. Imports the necessary libraries and routes requests
*/
// import Node.JS Environmental variables
require('dotenv').config();
const host = process.env.HOST || 'http://localhost';
const port = process.env.PORT || '3000';
// NPM Imports
var express = require('express');
var createError = require('createerror');
var cors = require('cors');
var whiskers = require('whiskers'); // Whiskers rendering engine
var path = require('path');
// Express Router Imports
const mapRouter = require("./routes/map");
const homeRouter = require('./routes/home');
const resourcesRouter = require('./routes/resources');
// Create express app
var app = express(); // needs to be set up with websockets
// allow requests to Amazon AWS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
// allow CORS
app.use(cors());
// set view engine to just plain ol' html
app.use(express.static(__dirname + '/public'));
// set view engine to whiskers
app.engine('.html', whiskers.__express);
app.set('views', path.join(__dirname, '/public'));
// Connect the Express files to their respective Routers and Login Requirement functions
app.use('/', homeRouter);
app.use('/map', mapRouter);
app.use('/resources', resourcesRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
// Start the server!!! 😁
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
module.exports = app;