pg-rest-api/index.js

30 lines
760 B
JavaScript
Raw Normal View History

2022-05-02 22:28:04 +02:00
const DEBUG=require('debug')('index');
2022-05-06 11:57:43 +02:00
const HTTPS = require('https');
const FS = require('fs');
2022-05-02 22:28:04 +02:00
DEBUG('index start...');
2023-12-21 07:22:40 +01:00
const main=require('./src/main');
2022-05-02 22:28:04 +02:00
//TODO make port available via config
//set port
const PORT=parseInt(process.env.PORT, 10)||65535;
2022-05-06 11:57:43 +02:00
DEBUG('PORT: '+PORT);
2022-05-02 22:28:04 +02:00
//TODO make env available via config
2023-12-21 07:22:40 +01:00
//pass 'main' to server
2022-05-02 22:28:04 +02:00
DEBUG('NODE_ENV: '+process.env.NODE_ENV);
if (process.env.NODE_ENV !== 'production') {
2022-05-06 11:57:43 +02:00
DEBUG('development mode');
2023-12-21 07:22:40 +01:00
main.listen(PORT);
2022-05-02 22:28:04 +02:00
}else{
2022-05-06 11:57:43 +02:00
DEBUG('production mode');
HTTPS.createServer({
//TODO make key and cert available via config
key: FS.readFileSync('./p'),
cert: FS.readFileSync('./f')
2023-12-21 07:22:40 +01:00
}, main)
2022-05-06 11:57:43 +02:00
.listen(PORT, ()=>DEBUG('listening on port '+PORT));
2022-05-02 22:28:04 +02:00
}
2022-05-06 11:57:43 +02:00
DEBUG('index done.');