-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebServer.js
36 lines (28 loc) · 962 Bytes
/
webServer.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
require('dotenv').config({ silent: true });
var express = require('express');
var path = require('path');
var routes = require('./src/server-app/routes')
var bodyParser = require('body-parser')
var jwt = require('express-jwt')
var app = express();
app.use(express.static(path.resolve(__dirname)))
app.use(bodyParser.json());
app.use('/api', jwt({ secret: process.env.SECRET }).unless({ path: ['/api/login'] }))
module.exports.app = app;
module.exports.start = function start(port, callback) {
routes.use(app);
//this should be updating to ignore api calls
app.get('/*', function (req, res) {
res.sendFile(path.resolve(__dirname, './index.html'))
})
app.use(function (err, req, res, next) {
if (err) {
console.log('an error has occurred', err);
}
next();
})
callback = callback || function () {
console.log(`Listening on port ${port}`)
}
app.listen(port, callback);
}