-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
74 lines (40 loc) · 1.25 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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
var passport = require('passport');
// API file for interacting with MongoDB
const api = require('./server/routes/api');
// Passport config
require('./server/config/passport');
//Set Port
const port = '3000';
//create express server
const app = express();
// Angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist')));
// Body Parsers Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));
// Passport Middleware
app.use(passport.initialize());
app.use(passport.session());
// API location
app.use('/api', api);
// app.get('/admin', (req, res) => {
// res.sendFile(path.join(__dirname, 'src/app/admin-page/admin-page.component.html'));
// });
// default route
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.listen(port, function(){
console.log(" Server Running on localhost: "+ port)});
// error handlers
// [SH] Catch unauthorised errors
app.use(function (err, req, res, next) {
if (err.name === 'UnauthorizedError') {
res.status(401);
res.json({"message" : err.name + ": " + err.message});
}
});
module.exports = app;