This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
53 lines (43 loc) · 1.56 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
/**
* Imagino Imaginis
* ----------------------------------------------------------------
* This is the core API server, served on https.
* It serves as the middleware between the database and the front-end and stylizer.
* This API may also be used by users outside of the website, provided they are a paid user.
*/
const express = require('express');
const bodyParser = require('body-parser'); // required to parse JSON
const mountRoutes = require('./app/routes');
const https = require('https'); // serve on https
const fs = require('fs');
const app = express();
var config;
try {
config = require('./config.js');
} catch (e) {
console.log("ERROR: Could not find `config.js`. Have you tried copying `config.js.template` to `config.js` (and populating the relevant fields)?");
process.exit(1);
}
// Allows for cross-origin resource sharing
// https://github.com/expressjs/cors
var cors = require('cors');
var helmet = require('helmet');
const port = 8000;
console.log(__dirname);
//This allows Express to process URL encoded forms on its own.
//This way, we don't get undefined when receiving JSON
app.use(bodyParser.json());
app.use(bodyParser.raw({limit: '50mb'}));
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
app.use(cors());
app.use(helmet());
console.log(config);
app.use(express.static(config.serve));
const options = {
cert: fs.readFileSync('./fullchain.pem'),
key: fs.readFileSync('./privkey.pem')
}
require('./app/routes')(app);
https.createServer(options, app).listen(port, () => {
console.log('We are live on ' + port);
});