liftie 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.js CHANGED
@@ -8,6 +8,7 @@ import gzip from 'connect-gzip-static';
8
8
  import renderer from 'connect-renderer';
9
9
  import errorHandler from 'errorhandler';
10
10
  import logger from 'morgan';
11
+ import { NODE_ENV, PORT, SITE_URL as siteUrl, LIFTIE_STATIC_HOST as staticHost } from './lib/env.js';
11
12
  import lifts from './lib/lifts/index.js';
12
13
  import loader from './lib/loader.js';
13
14
  import * as loaders from './lib/loaders.js';
@@ -21,12 +22,8 @@ import webcams from './lib/webcams.js';
21
22
  const app = connect();
22
23
  export default app;
23
24
 
24
- process.env.PORT ??= 3000;
25
- process.env.SITE_URL ??= `http://localhost:${process.env.PORT}`;
26
- process.env.NODE_ENV ??= 'development';
27
-
28
- const root = path.join(path.dirname(new URL(import.meta.url).pathname), 'public');
29
- const { SITE_URL: siteUrl, LIFTIE_STATIC_HOST: staticHost = '' } = process.env;
25
+ const root = path.resolve(import.meta.dirname, 'public');
26
+ const views = path.resolve(import.meta.dirname, 'views');
30
27
 
31
28
  const cachify = cachifyStatic(root, { format: 'name' });
32
29
 
@@ -42,9 +39,9 @@ app.locals = {
42
39
  };
43
40
 
44
41
  app.use(
45
- renderer(`${path.dirname(new URL(import.meta.url).pathname)}/views`).engine('jade', {
42
+ renderer(views).engine('jade', {
46
43
  compile,
47
- options: { compileDebug: process.env.NODE_ENV !== 'production' }
44
+ options: { compileDebug: NODE_ENV !== 'production' }
48
45
  })
49
46
  );
50
47
 
@@ -61,7 +58,7 @@ app.use(async (req, res, next) => {
61
58
 
62
59
  app.use(gzip(root));
63
60
 
64
- if (process.env.NODE_ENV === 'development') {
61
+ if (NODE_ENV === 'development') {
65
62
  app.locals.min = '';
66
63
  app.use(errorHandler());
67
64
  }
@@ -86,8 +83,8 @@ app.run = function run() {
86
83
  process.exit(1);
87
84
  return;
88
85
  }
89
- http.createServer(app).listen(process.env.PORT, () => {
90
- console.log(`Running on: http://localhost:${process.env.PORT}`);
86
+ http.createServer(app).listen(PORT, () => {
87
+ console.log(`Running on: http://localhost:${PORT}`);
91
88
  });
92
89
  });
93
90
  };
package/lib/env.js ADDED
@@ -0,0 +1,28 @@
1
+ import { tmpdir } from 'node:os';
2
+
3
+ const {
4
+ CSP_REPORT_URI,
5
+ LIFTIE_CSP_ENFORCE,
6
+ LIFTIE_STATIC_HOST = '',
7
+ LOG_DIR = tmpdir(),
8
+ NODE_ENV = 'development',
9
+ OPENWEATHER_API_KEY,
10
+ PORT = 3000,
11
+ WEBCAMS_API_KEY
12
+ } = process.env;
13
+
14
+ process.env.SITE_URL ??= `http://localhost:${PORT}`;
15
+
16
+ const { SITE_URL } = process.env;
17
+
18
+ export {
19
+ CSP_REPORT_URI,
20
+ LIFTIE_CSP_ENFORCE,
21
+ LIFTIE_STATIC_HOST,
22
+ LOG_DIR,
23
+ NODE_ENV,
24
+ OPENWEATHER_API_KEY,
25
+ PORT,
26
+ SITE_URL,
27
+ WEBCAMS_API_KEY
28
+ };
@@ -1,9 +1,9 @@
1
- import { tmpdir } from 'node:os';
2
1
  import path from 'node:path';
2
+ import { LOG_DIR } from '../env.js';
3
3
  import * as plugins from '../plugins.js';
4
4
  import dbCache from './cache.js';
5
5
 
6
- const dbFileName = path.resolve(process.env.LOG_DIR || tmpdir(), 'liftie.db.json');
6
+ const dbFileName = path.resolve(LOG_DIR, 'liftie.db.json');
7
7
 
8
8
  // persistent storage status for each resort
9
9
  export default function database(cache) {
@@ -1,9 +1,8 @@
1
1
  import crypto from 'node:crypto';
2
+ import { CSP_REPORT_URI, LIFTIE_CSP_ENFORCE, LIFTIE_STATIC_HOST as staticHost } from '../env.js';
2
3
 
3
4
  export default [csp, referrer, feature, link];
4
5
 
5
- const { LIFTIE_STATIC_HOST: staticHost = '', LIFTIE_CSP_ENFORCE, CSP_REPORT_URI } = process.env;
6
-
7
6
  const scriptHost = staticHost ? staticHost : `'self'`;
8
7
 
9
8
  const CSP_HEADER_NAME = toBoolean(LIFTIE_CSP_ENFORCE)
@@ -40,7 +39,10 @@ function referrer(_req, res, next) {
40
39
  }
41
40
 
42
41
  function feature(_req, res, next) {
43
- res.setHeader('Permissions-Policy', `fullscreen 'self'`);
42
+ res.setHeader(
43
+ 'Permissions-Policy',
44
+ 'camera=(), microphone=(), geolocation=(), usb=(), payment=(), autoplay=(), fullscreen=(self), ch-ua=(self), ch-ua-platform=(self), ch-ua-mobile=(self), ch-ua-arch=(self), ch-ua-model=(self)'
45
+ );
44
46
  next();
45
47
  }
46
48
 
@@ -1,6 +1,6 @@
1
+ import querystring from 'node:querystring';
1
2
  import Router from '@pirxpilot/router';
2
3
  import parseurl from 'parseurl';
3
- import qs from 'qs';
4
4
  import canonical from './canonical.js';
5
5
  import headers from './headers.js';
6
6
  import plan from './plan.js';
@@ -189,7 +189,7 @@ export default function routes(app) {
189
189
  });
190
190
 
191
191
  router.use((req, _res, next) => {
192
- req.query = qs.parse(parseurl(req).query);
192
+ req.query = querystring.parse(parseurl(req).query);
193
193
  next();
194
194
  });
195
195
  router.get('/', reqData, headers, index, renderResorts);
@@ -1,12 +1,9 @@
1
- import qs from 'qs';
2
-
3
1
  export default function addToTrip(resort) {
4
- return qs.stringify({
5
- stop: {
6
- name: resort.name,
7
- coordinates: { lon: resort.ll[0], lat: resort.ll[1] },
8
- url: resort.href,
9
- duration: 7 * 60 * 60 * 1000
10
- }
11
- });
2
+ const params = new URLSearchParams();
3
+ params.set('stop[name]', resort.name);
4
+ params.set('stop[coordinates][lon]', resort.ll[0]);
5
+ params.set('stop[coordinates][lat]', resort.ll[1]);
6
+ params.set('stop[url]', resort.href);
7
+ params.set('stop[duration]', 7 * 60 * 60 * 1000);
8
+ return params.toString();
12
9
  }
@@ -1,8 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import esbuild from 'esbuild';
3
3
  import packageJSON from '../../package.json' with { type: 'json' };
4
-
5
- const { NODE_ENV, SITE_URL: siteUrl, LIFTIE_STATIC_HOST: staticHost = '' } = process.env;
4
+ import { NODE_ENV, SITE_URL as siteUrl, LIFTIE_STATIC_HOST as staticHost } from '../env.js';
6
5
 
7
6
  const DEBUG = NODE_ENV !== 'production';
8
7
 
@@ -1,3 +1,4 @@
1
+ import { OPENWEATHER_API_KEY } from '../env.js';
1
2
  import { hour } from '../tools/millis.js';
2
3
  import noaa from './noaa.js';
3
4
  import openweather from './openweather.js';
@@ -7,10 +8,9 @@ fetch.interval = {
7
8
  inactive: Number.POSITIVE_INFINITY // don't fetch on inactive
8
9
  };
9
10
 
10
- // see: https://openweathermap.org/forecast5
11
- const { OPENWEATHER_API_KEY } = process.env;
12
-
13
11
  export default function fetch(resort, fn) {
12
+ // see: https://openweathermap.org/forecast5
13
+
14
14
  if (resort.noaa) {
15
15
  noaa(resort, fn);
16
16
  } else if (OPENWEATHER_API_KEY) {
@@ -1,14 +1,11 @@
1
1
  import Debug from 'debug';
2
+ import { LIFTIE_STATIC_HOST as staticHost } from '../env.js';
3
+ import { iconsFromUrl } from './icons.js';
2
4
 
3
5
  const debug = Debug('liftie:weather');
4
6
 
5
- import { iconsFromUrl } from './icons.js';
6
- export default fetchWeather;
7
-
8
7
  const userAgent = 'Mozilla/5.0 (compatible; Liftie/1.0; +https://liftie.info)';
9
8
 
10
- const { LIFTIE_STATIC_HOST: staticHost = '' } = process.env;
11
-
12
9
  function normalize(data, ll) {
13
10
  debug('weather %j', data.properties.periods);
14
11
 
@@ -31,7 +28,7 @@ function normalize(data, ll) {
31
28
  };
32
29
  }
33
30
 
34
- function fetchWeather(resort, fn) {
31
+ export default function fetchWeather(resort, fn) {
35
32
  debug('fetch weather from NOAA for %s', resort.id);
36
33
 
37
34
  const { ll } = resort;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liftie",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "Clean, simple, easy to read, fast ski resort lift status",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -52,13 +52,12 @@
52
52
  "lodash": "^4.16.6",
53
53
  "morgan": "^1.9.0",
54
54
  "parseurl": "^1.3.3",
55
- "qs": "^6.13.1",
56
55
  "ro-rating": "~2",
57
56
  "tiny-pager": "^2.0.0",
58
57
  "to-title-case": "^1.0.0"
59
58
  },
60
59
  "devDependencies": {
61
- "@biomejs/biome": "2.3.10",
60
+ "@biomejs/biome": "2.3.11",
62
61
  "@pirxpilot/stylus": "^1.2.0",
63
62
  "commander": "~14",
64
63
  "postcss": "~8",