convert server to mjs

This commit is contained in:
Matt Walsh
2025-03-22 13:19:36 +01:00
parent cab2da5e62
commit c2f0b9bf3f
13 changed files with 43 additions and 32 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,5 @@
node_modules
**/debug.log
server/scripts/custom.js
server/scripts/custom.js
music

4
.vscode/launch.json vendored
View File

@@ -50,7 +50,7 @@
"skipFiles": [
"<node_internals>/**",
],
"program": "${workspaceFolder}/index.js",
"program": "${workspaceFolder}/index.mjs",
},
{
"type": "node",
@@ -59,7 +59,7 @@
"skipFiles": [
"<node_internals>/**",
],
"program": "${workspaceFolder}/index.js",
"program": "${workspaceFolder}/index.mjs",
"env": {
"DIST": "1"
}

View File

@@ -1,13 +1,13 @@
// pass through api requests
// http(s) modules
const https = require('https');
import https from 'https';
// url parsing
const queryString = require('querystring');
import queryString from 'querystring';
// return an express router
module.exports = (req, res) => {
const cors = (req, res) => {
// add out-going headers
const headers = {};
headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)';
@@ -41,3 +41,5 @@ module.exports = (req, res) => {
console.error(e);
});
};
export default cors;

View File

@@ -1,13 +1,13 @@
// pass through api requests
// http(s) modules
const https = require('https');
import https from 'https';
// url parsing
const queryString = require('querystring');
import queryString from 'querystring';
// return an express router
module.exports = (req, res) => {
const outlook = (req, res) => {
// add out-going headers
const headers = {};
headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)';
@@ -42,3 +42,5 @@ module.exports = (req, res) => {
console.error(e);
});
};
export default outlook;

View File

@@ -1,13 +1,13 @@
// pass through api requests
// http(s) modules
const https = require('https');
import https from 'https';
// url parsing
const queryString = require('querystring');
import queryString from 'querystring';
// return an express router
module.exports = (req, res) => {
const radar = (req, res) => {
// add out-going headers
const headers = {};
headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)';
@@ -42,3 +42,5 @@ module.exports = (req, res) => {
console.error(e);
});
};
export default radar;

View File

@@ -1,19 +1,15 @@
// express
const express = require('express');
import express from 'express';
import fs from 'fs';
import corsPassThru from './cors/index.mjs';
import radarPassThru from './cors/radar.mjs';
import outlookPassThru from './cors/outlook.mjs';
const app = express();
const port = process.env.WS4KP_PORT ?? 8080;
const path = require('path');
// template engine
app.set('view engine', 'ejs');
// cors pass through
const fs = require('fs');
const corsPassThru = require('./cors');
const radarPassThru = require('./cors/radar');
const outlookPassThru = require('./cors/outlook');
// cors pass-thru to api.weather.gov
app.get('/stations/*', corsPassThru);
app.get('/Conus/*', radarPassThru);
@@ -23,7 +19,7 @@ app.get('/products/*', outlookPassThru);
const { version } = JSON.parse(fs.readFileSync('package.json'));
const index = (req, res) => {
res.render(path.join(__dirname, 'views/index'), {
res.render('index', {
production: false,
version,
});
@@ -32,15 +28,15 @@ const index = (req, res) => {
// debugging
if (process.env?.DIST === '1') {
// distribution
app.use('/images', express.static(path.join(__dirname, './server/images')));
app.use('/fonts', express.static(path.join(__dirname, './server/fonts')));
app.use('/scripts', express.static(path.join(__dirname, './server/scripts')));
app.use('/', express.static(path.join(__dirname, './dist')));
app.use('/images', express.static('./server/images'));
app.use('/fonts', express.static('./server/fonts'));
app.use('/scripts', express.static('./server/scripts'));
app.use('/', express.static('./dist'));
} else {
// debugging
app.get('/index.html', index);
app.get('/', index);
app.get('*', express.static(path.join(__dirname, './server')));
app.get('*', express.static('./server'));
}
const server = app.listen(port, () => {

View File

@@ -2,7 +2,8 @@
"name": "ws4kp",
"version": "5.14.3",
"description": "Welcome to the WeatherStar 4000+ project page!",
"main": "index.js",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:css": "sass --style=compressed ./server/styles/scss/main.scss ./server/styles/main.css",
@@ -48,4 +49,4 @@
"express": "^4.17.1",
"ejs": "^3.1.5"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
.media {
display: none;
}

View File

@@ -11,4 +11,5 @@
@import 'radar';
@import 'regional-forecast';
@import 'almanac';
@import 'hazards';
@import 'hazards';
@import 'media';

0
src/music-list.mjs Normal file
View File

View File

@@ -131,6 +131,7 @@
<img id="NavigateRefresh" class="navButton" src="images/nav/ic_refresh_white_24dp_2x.png" title="Refresh" />
</div>
<div id="divTwcBottomRight">
<img id="ToggleMedia" class="navButton" src="images/nav/ic_volume_off_white_24dp_2x.png" title="Unmute" />
<img id="ToggleFullScreen" class="navButton" src="images/nav/ic_fullscreen_white_24dp_2x.png" title="Enter Fullscreen" />
</div>
</div>
@@ -141,6 +142,7 @@
<div class="info">
<a href="https://github.com/netbymatt/ws4kp#weatherstar-4000">More information</a>
</div>
<div class="media"></div>
<div class='heading'>Selected displays</div>
<div id='enabledDisplays'>