-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (30 loc) · 997 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (30 loc) · 997 Bytes
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
var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');
const path = require('path');
const app = express();
app.use(bodyParser.text({
type: function(req) {
return 'text';
}
}));
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// Put all API endpoints under '/api'
app.post('/post', function (req, res) {
console.log(req.body);
res = res.status(200);
if (req.get('Content-Type')) {
console.log("Content-Type: " + req.get('Content-Type'));
res = res.type(req.get('Content-Type'));
}
res.send(req.body);
});
// The "catchall" handler: for any request that doesn't
// match one above, send back React's index.html file.
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
const port = process.env.PORT || 7777;
http.createServer(app).listen(port);
console.log(`Server listening on ${port}`);