-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
58 lines (46 loc) · 2.14 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
/**
* @file Application entry point/Server configuration
* @author Omar Taylor <omtaylor@iastate.edu>
*/
'use strict';
global.appRoot = __dirname; //set the global path so other files may use it
require('dotenv').config();
const express = require('express'), // Require our module
app = express(), // Instantiate our module
compression = require('compression'), // Require compression module
bodyParser = require('body-parser'), // Parses incoming request bodies (made available in req.body)
port = 80, // Set to port 80
morgan = require('morgan'), // Require our server activity logger module
minifyHTML = require('express-minify-html'), // Require HTML minification module for faster load times (Not useful for this application, but good practice)
Weather = require('./app/weather/weather').Weather; // Require our weather class
app.use(compression(), morgan('dev'), bodyParser.urlencoded({extended: true}), bodyParser.json()); // Attach middleware
// Configure minification module
app.use(minifyHTML({
override: true,
exception_url: false,
htmlMinifier: {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true,
minifyJS: true
}
}));
app.use(express.static('./public')); // Serve up public folder
app.use(express.static('./node_modules/bootstrap/dist')); // Serve up bootstrap folder
app.use(express.static('./node_modules/jquery/dist')); // Serve up jquery folder
app.use(express.static('./node_modules/materialize-css/dist')); // Server up fancy external css and js folder
const weather = new Weather(process.env.APIKEY, __dirname + '/public/files/city.list.json', err => {
if (err) {
console.log(err);
}
}); // Instantiate weather class
require(__dirname + '/app/routes/routes.js')(app, weather); // load our routes and pass in our app
// Start server (check for parent for testing purposes)
if (!module.parent) {
app.listen(port, () => {
console.log("Listening on port " + port); // Successfully started (not checking for errors)
});
}
module.exports.app = app;