ws4kp-linhanced/index.js

47 lines
1 KiB
JavaScript
Raw Normal View History

2020-09-04 13:02:20 -05:00
// express
const express = require('express');
2020-12-29 09:58:01 -06:00
2020-09-04 13:02:20 -05:00
const app = express();
2020-12-29 09:58:01 -06:00
const port = process.env.WS4KP_PORT ?? 8080;
2020-09-04 13:02:20 -05:00
const path = require('path');
// template engine
app.set('view engine', 'ejs');
// cors pass through
const corsPassThru = require('./cors');
2020-09-04 17:03:03 -05:00
const radarPassThru = require('./cors/radar');
2020-09-23 14:43:49 -05:00
const outlookPassThru = require('./cors/outlook');
2020-09-04 13:02:20 -05:00
// cors pass-thru to api.weather.gov
app.get('/stations/*', corsPassThru);
2020-09-04 17:03:03 -05:00
app.get('/Conus/*', radarPassThru);
2020-09-23 14:43:49 -05:00
app.get('/products/*', outlookPassThru);
2020-09-04 13:02:20 -05:00
2020-09-08 14:39:17 -05:00
// version
const version = require('./version');
2020-09-04 13:02:20 -05:00
const index = (req, res) => {
res.render(path.join(__dirname, 'views/index'), {
production: false,
2020-09-08 14:39:17 -05:00
version,
2020-09-04 13:02:20 -05:00
});
};
2020-10-20 16:33:44 +00:00
// main page
2020-09-04 13:02:20 -05:00
app.get('/index.html', index);
app.get('/', index);
// fallback
2020-10-20 16:33:44 +00:00
app.get('*', express.static(path.join(__dirname, './server')));
2020-09-04 13:02:20 -05:00
const server = app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
// graceful shutdown
process.on('SIGINT', () => {
server.close(()=> {
console.log('Server closed');
});
});