-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (30 loc) · 1.12 KB
/
Copy pathapp.js
File metadata and controls
40 lines (30 loc) · 1.12 KB
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
const express = require('express');
const app = express();
const cors = require('cors');
const bodyParser = require('body-parser');
// const jwt = require('./backend/_helpers/jwt');
// const errorHandler = require('./backend/_helpers/error-handler');
const path = require('path');
// const sendMailToUser = require('./backend/_helpers/mail');
// const db = require('./backend/_helpers/db');
// const User = db.User;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors());
app.use(express.static(__dirname + '/public'));
//to load home page
app.use(express.static(path.join(__dirname, 'dist')));
// use JWT auth to secure the api
// app.use(jwt());
// api routes
app.use('/users', require(path.join(__dirname,'/backend/users/user.controller.js')));
// global error handler
// app.use(errorHandler);
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, './dist/index.html'));
});
// start server
const port = process.env.NODE_ENV === 'production' ? (process.env.PORT || 80) : 3000;
const server = app.listen(port, function () {
console.log('Server listening on port ' + port);
});