Skip to content

Commit c2f0b9b

Browse files
committed
convert server to mjs
1 parent cab2da5 commit c2f0b9b

File tree

13 files changed

+43
-32
lines changed

13 files changed

+43
-32
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
**/debug.log
3-
server/scripts/custom.js
3+
server/scripts/custom.js
4+
music
5+

Diff for: .vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"skipFiles": [
5151
"<node_internals>/**",
5252
],
53-
"program": "${workspaceFolder}/index.js",
53+
"program": "${workspaceFolder}/index.mjs",
5454
},
5555
{
5656
"type": "node",
@@ -59,7 +59,7 @@
5959
"skipFiles": [
6060
"<node_internals>/**",
6161
],
62-
"program": "${workspaceFolder}/index.js",
62+
"program": "${workspaceFolder}/index.mjs",
6363
"env": {
6464
"DIST": "1"
6565
}

Diff for: cors/index.js renamed to cors/index.mjs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// pass through api requests
22

33
// http(s) modules
4-
const https = require('https');
4+
import https from 'https';
55

66
// url parsing
7-
const queryString = require('querystring');
7+
import queryString from 'querystring';
88

99
// return an express router
10-
module.exports = (req, res) => {
10+
const cors = (req, res) => {
1111
// add out-going headers
1212
const headers = {};
1313
headers['user-agent'] = '(WeatherStar 4000+, [email protected])';
@@ -41,3 +41,5 @@ module.exports = (req, res) => {
4141
console.error(e);
4242
});
4343
};
44+
45+
export default cors;

Diff for: cors/outlook.js renamed to cors/outlook.mjs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// pass through api requests
22

33
// http(s) modules
4-
const https = require('https');
4+
import https from 'https';
55

66
// url parsing
7-
const queryString = require('querystring');
7+
import queryString from 'querystring';
88

99
// return an express router
10-
module.exports = (req, res) => {
10+
const outlook = (req, res) => {
1111
// add out-going headers
1212
const headers = {};
1313
headers['user-agent'] = '(WeatherStar 4000+, [email protected])';
@@ -42,3 +42,5 @@ module.exports = (req, res) => {
4242
console.error(e);
4343
});
4444
};
45+
46+
export default outlook;

Diff for: cors/radar.js renamed to cors/radar.mjs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// pass through api requests
22

33
// http(s) modules
4-
const https = require('https');
4+
import https from 'https';
55

66
// url parsing
7-
const queryString = require('querystring');
7+
import queryString from 'querystring';
88

99
// return an express router
10-
module.exports = (req, res) => {
10+
const radar = (req, res) => {
1111
// add out-going headers
1212
const headers = {};
1313
headers['user-agent'] = '(WeatherStar 4000+, [email protected])';
@@ -42,3 +42,5 @@ module.exports = (req, res) => {
4242
console.error(e);
4343
});
4444
};
45+
46+
export default radar;

Diff for: index.js renamed to index.mjs

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
// express
2-
const express = require('express');
1+
import express from 'express';
2+
import fs from 'fs';
3+
import corsPassThru from './cors/index.mjs';
4+
import radarPassThru from './cors/radar.mjs';
5+
import outlookPassThru from './cors/outlook.mjs';
36

47
const app = express();
58
const port = process.env.WS4KP_PORT ?? 8080;
6-
const path = require('path');
79

810
// template engine
911
app.set('view engine', 'ejs');
1012

11-
// cors pass through
12-
const fs = require('fs');
13-
const corsPassThru = require('./cors');
14-
const radarPassThru = require('./cors/radar');
15-
const outlookPassThru = require('./cors/outlook');
16-
1713
// cors pass-thru to api.weather.gov
1814
app.get('/stations/*', corsPassThru);
1915
app.get('/Conus/*', radarPassThru);
@@ -23,7 +19,7 @@ app.get('/products/*', outlookPassThru);
2319
const { version } = JSON.parse(fs.readFileSync('package.json'));
2420

2521
const index = (req, res) => {
26-
res.render(path.join(__dirname, 'views/index'), {
22+
res.render('index', {
2723
production: false,
2824
version,
2925
});
@@ -32,15 +28,15 @@ const index = (req, res) => {
3228
// debugging
3329
if (process.env?.DIST === '1') {
3430
// distribution
35-
app.use('/images', express.static(path.join(__dirname, './server/images')));
36-
app.use('/fonts', express.static(path.join(__dirname, './server/fonts')));
37-
app.use('/scripts', express.static(path.join(__dirname, './server/scripts')));
38-
app.use('/', express.static(path.join(__dirname, './dist')));
31+
app.use('/images', express.static('./server/images'));
32+
app.use('/fonts', express.static('./server/fonts'));
33+
app.use('/scripts', express.static('./server/scripts'));
34+
app.use('/', express.static('./dist'));
3935
} else {
4036
// debugging
4137
app.get('/index.html', index);
4238
app.get('/', index);
43-
app.get('*', express.static(path.join(__dirname, './server')));
39+
app.get('*', express.static('./server'));
4440
}
4541

4642
const server = app.listen(port, () => {

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "ws4kp",
33
"version": "5.14.3",
44
"description": "Welcome to the WeatherStar 4000+ project page!",
5-
"main": "index.js",
5+
"main": "index.mjs",
6+
"type": "module",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1",
89
"build:css": "sass --style=compressed ./server/styles/scss/main.scss ./server/styles/main.css",
@@ -48,4 +49,4 @@
4849
"express": "^4.17.1",
4950
"ejs": "^3.1.5"
5051
}
51-
}
52+
}

Diff for: server/styles/main.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: server/styles/main.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: server/styles/scss/_media.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.media {
2+
display: none;
3+
}

Diff for: server/styles/scss/main.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
@import 'radar';
1212
@import 'regional-forecast';
1313
@import 'almanac';
14-
@import 'hazards';
14+
@import 'hazards';
15+
@import 'media';

Diff for: src/music-list.mjs

Whitespace-only changes.

Diff for: views/index.ejs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<img id="NavigateRefresh" class="navButton" src="images/nav/ic_refresh_white_24dp_2x.png" title="Refresh" />
132132
</div>
133133
<div id="divTwcBottomRight">
134+
<img id="ToggleMedia" class="navButton" src="images/nav/ic_volume_off_white_24dp_2x.png" title="Unmute" />
134135
<img id="ToggleFullScreen" class="navButton" src="images/nav/ic_fullscreen_white_24dp_2x.png" title="Enter Fullscreen" />
135136
</div>
136137
</div>
@@ -141,6 +142,7 @@
141142
<div class="info">
142143
<a href="https://github.com/netbymatt/ws4kp#weatherstar-4000">More information</a>
143144
</div>
145+
<div class="media"></div>
144146

145147
<div class='heading'>Selected displays</div>
146148
<div id='enabledDisplays'>

0 commit comments

Comments
 (0)