forked from classroom-angel/labs11_prop_mngmt-BE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (25 loc) · 862 Bytes
/
index.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
const express = require('express');
const cors = require('cors');
const server = express();
const DEV_URLS = ['http://localhost:3000'];
const PROD_URLS = ['https://www.classroomangel.us'];
const whitelist = process.env.NODE_ENV === 'production' ? PROD_URLS : DEV_URLS;
const corsOptions = {
origin: (origin, cb) => {
// return whitelist.indexOf(origin) !== -1
// ? cb(null, true);
// : cb(new Error('Not allowed by CORS'));
return cb(null, true);
}
};
server.use(cors(corsOptions));
server.use(express.json());
server.use('/api', require('./api'));
server.get('', (req, res) => {
res.json({
success: `You're not insane! See the API docs at: https://classroomangeldocs.surge.sh`
});
});
const PORT = process.env.PORT || 8000;
server.listen(PORT, () => console.log(`Server listening on port ${PORT}.`));
module.exports = server;