-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (46 loc) · 1.43 KB
/
server.js
File metadata and controls
53 lines (46 loc) · 1.43 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
41
42
43
44
45
46
47
48
49
50
51
52
53
require('dotenv').config()
let express = require('express');
let cors = require('cors');
let bodyParser = require('body-parser');
//require('./server/database/db-conn');
require('./server/database/db-conn-azure');
// ****Initialize app**********
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cors());
// Configure Routes
const studentRoute = require('./server/routes/student.route')
app.use('/students', studentRoute)
app.get('/authKeys', (req, res) => {
res.json({
GOOGLE_CLIENTID: process.env.GOOGLE_CLIENTID,
FACEBOOK_APPID: process.env.FACEBOOK_APPID,
TWITTER_KEY: process.env.TWITTER_KEY,
TWITTER_SECRET: process.env.TWITTER_SECRET,
MICROSOFT_APPID: process.env.MICROSOFT_APPID,
INSTAGRAM_CLIENTID: process.env.INSTAGRAM_CLIENTID
})
})
// Configure client app
app.use(express.static('./client/build/'));
// * is very important, as it enabled all the reactjs routes!
app.get('/*', (req, res) => {
res.sendFile('index.html', {root: './client/build/'});
})
// PORT
const port = process.env.PORT || 4000;
const server = app.listen(port, () => {
console.log('Connected to port ' + port)
})
// 404 Error
app.use((req, res, next) => {
next(createError(404));
});
app.use(function (err, req, res, next) {
console.error(err.message);
if (!err.statusCode) err.statusCode = 500;
res.status(err.statusCode).send(err.message);
});