-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.js
More file actions
30 lines (24 loc) · 773 Bytes
/
Server.js
File metadata and controls
30 lines (24 loc) · 773 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
const express = require('express');
const app = express();
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
app.use(bodyParser.json());
function endsWith(str, subStr) {
return str.indexOf(subStr) === str.length - subStr.length;
}
app.use((req, res, next) => {
res.set('Cross-Origin-Embedder-Policy', 'require-corp');
res.set('Cross-Origin-Opener-Policy', 'same-origin');
if (endsWith(req.url, '.js')) {
res.contentType('application/javascript');
}
next();
// res.sendFile(path.join(__dirname, 'build/'));
});
app.use(express.static(path.join(__dirname, 'build')));
// app.use(cors());
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log('Listening on port', port);
});