-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpress.js
More file actions
46 lines (39 loc) · 1.55 KB
/
express.js
File metadata and controls
46 lines (39 loc) · 1.55 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
// require('dotenv').config();
const path = require('path');
const express = require('express');
// Initiaize Instance of Express as app
const app = express();
// POST Requests: In order to accept post requests, you must use bodyParser
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'build')));
/*---------------------------
| !IMPORTANT :: Should not be done in Production, only for local dev
| Bypassing CORS so express can be on port 5000 and react can be on 3000
| In production you would have Express access a static build of your app.
---------------------------*/
app.use((request, response, next) => {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
/*---------------------------
| Route Collections
---------------------------*/
const routes = require('./express-routes/index.js');
//app.use('/api/colors', routes.colors);
app.use('/api/tabbed', routes.tabbed);
app.use('/api/rooms', routes.rooms);
app.use('/api/slides', routes.slides);
app.use('/api/email', routes.email);
app.use('/api/login', routes.login);
// Catchall for requests that do not match our routing
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});//
// Heroku hook to use dynamic port binding
const PORT = process.env.PORT || 5000;
app.listen(PORT);
console.log('App is listening on port ' + PORT);