-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathserver.js
81 lines (71 loc) · 2.21 KB
/
server.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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Authored by Runpeng Liu,
* Brain Power (2018)
*/
const fs = require('fs');
const express = require('express');
const http = require('http');
const path = require('path');
const morgan = require('morgan');
const compress = require('compression');
const methodOverride = require('method-override');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const helmet = require('helmet');
const aws = require('aws-sdk');
const config = require('./local_config');
process.env.local = true;
process.env.AWS_REGION = config.AWS_REGION || "us-east-1";
process.env.FFMPEG_CMD = config.FFMPEG_CMD;
process.env.PRODUCER_START_TIMESTAMP_KEY = config.PRODUCER_START_TIMESTAMP_KEY || "producer_start_timestamp";
const app = express();
app.use(compress({
filter(req, res) {
return (/json|text|javascript|css|font|svg/).test(res.getHeader('Content-Type'));
},
level: 9
}));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json({
limit: '6mb'
}));
app.use(methodOverride());
app.use(cookieParser());
app.use(morgan('dev'));
app.use(helmet.frameguard());
app.use(helmet.xssFilter());
app.use(helmet.noSniff());
app.use(helmet.ieNoOpen());
app.use(helmet.hsts({
includeSubdomains: true,
force: true
}));
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
next();
});
app.disable('x-powered-by');
app.set('port', 3000);
app.use(express.static(path.join(__dirname, 'dashboard')));
const APIGatewayProxy = require("./lambda/WebApi");
const tmpDir = "./tmp";
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
}
app.post("/FrameData", APIGatewayProxy.processFrameData);
const sts = new aws.STS();
sts.getCallerIdentity({}, (err, data) => {
if (err) {
console.log(err);
process.exit(1);
} else {
process.env.UPLOADS_BUCKET_NAME = `${config.STACK_NAME}-uploads-${data.Account}`;
console.log("Uploads bucket: ", process.env.UPLOADS_BUCKET_NAME);
}
});
const server = http.createServer(app).listen(app.get('port'), () => {
console.log(`Express HTTP server listening on port ${app.get('port')}`);
});