-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
61 lines (47 loc) · 1.47 KB
/
Copy pathserver.ts
File metadata and controls
61 lines (47 loc) · 1.47 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
54
55
56
57
58
59
60
61
import 'zone.js/dist/zone-node';
require('dotenv').config();
import express from 'express';
import { join } from 'path';
import cookieParser from 'cookie-parser';
import apiRouter from './server/api/router_api';
import { init } from './server/init';
export function app(): express.Express
{
const server = express();
const distFolder = join(process.cwd(), 'dist/scotty-beam-app/browser');
server.use(express.json());
server.use(cookieParser());
server.use((req, res, next) =>
{
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, PATCH, PUT, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
server.options('*', (req, res) => {
// allowed XHR methods
res.header('Access-Control-Allow-Methods', 'GET, PATCH, PUT, POST, DELETE, OPTIONS');
res.send();
});
server.use('/api', apiRouter);
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
server.get('*', function (req, res)
{
res.sendFile(distFolder + '/index.html');
});
return server;
}
async function run()
{
const port = process.env.PORT || 4000;
// Start up the Node server
const server = app();
await init();
server.listen(port, () =>
{
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
run();