-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (25 loc) · 915 Bytes
/
index.js
File metadata and controls
27 lines (25 loc) · 915 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
const app = require('./app');
const config = require('./config');
const fs = require('fs');
const https = require('https');
if (process.env.PRODUCTION) {
const {domain} = config;
const privateKey = fs.readFileSync(`/etc/letsencrypt/live/${domain}/privkey.pem`, 'utf8');
const certificate = fs.readFileSync(`/etc/letsencrypt/live/${domain}/cert.pem`, 'utf8');
const ca = fs.readFileSync(`/etc/letsencrypt/live/${domain}/chain.pem`, 'utf8');
https.createServer({
key: privateKey,
cert: certificate,
ca: ca
}, app).listen(config.port, function () {
console.log(`API is now listening on port ${config.port}.`);
});
} else {
app.listen(config.port, function () {
console.log(`API is now listening in development mode on port ${config.port}.`);
});
}
process.on('SIGINT', function () {
console.log(`Exiting API.`);
process.exit();
});