-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·70 lines (53 loc) · 1.94 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
67
68
69
70
'use strict';
/*
SETUP
*/
const express = require('express'); // We are using the express library for the web server
var mysql = require('./db-connector.js');
var exprHandlebars = require('express-handlebars');
const app = express(); // We need to instantiate an express object to interact with the server in our code
//part of handlebars - dateformat module -- Used for displaying custom date format
const moment = require("moment");
//include custom handlebars helper function for formatting date
const handlebars = exprHandlebars.create({
helpers: {
dateFormat: function (date, options) {
const formatToUse = (arguments[1] && arguments[1].hash && arguments[1].hash.format) || "MM/DD/YYYY"
return moment(date).format(formatToUse);
}
},
defaultLayout: 'main'
})
//const PORT = 34118;
//added for Heroku deploy
let port = process.env.PORT;
if (port == null || port == "") {
port = 8000;
}
app.engine('handlebars', handlebars.engine);
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.set('view engine', 'handlebars');
app.set('mysql', mysql);
app.use('/static', express.static('public'));
app.use('/customers', require('./customers.js'));
app.use('/accounts', require('./accounts.js'));
app.use('/account_types', require('./account_types.js'));
app.use('/special_offers', require('./special_offers.js'));
app.use('/accounts_customers', require('./accounts_customers.js'));
app.use('/transactions', require('./transactions.js'));
app.use('/', express.static('public'));
app.use(function (req, res) {
res.status(404);
res.render('404');
});
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500);
res.render('500');
});
app.listen(port, function () {
console.log('Express started on http://localhost:' + port + '; press Ctrl-C to terminate.')
});