diff options
Diffstat (limited to 'app/lib/static.js')
-rw-r--r-- | app/lib/static.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/app/lib/static.js b/app/lib/static.js index ef48ae6..26fc231 100644 --- a/app/lib/static.js +++ b/app/lib/static.js @@ -1,13 +1,13 @@ -"use strict"; - -const Path = require("path"); -const url = require("url"); -const fs = require("fs"); +import {normalize, extname} from "node:path"; +import {parse as parseURL} from "node:url"; +import fs from "node:fs"; const mimeTypes = { ".html": "text/html", ".css": "text/css", ".js": "text/javascript", + ".cjs": "text/javascript", + ".mjs": "text/javascript", ".json": "application/json", ".wasm": "application/wasm", ".pdf": "application/pdf", @@ -32,7 +32,7 @@ const mimeTypes = { ".glb": "model/gltf-binary", }; -module.exports = class Static { +export default class Static { constructor(root) { this.root = `${root||"."}`; this.e404 = fs.readFileSync(`${this.root}/404.html`); @@ -46,8 +46,8 @@ module.exports = class Static { return; } - const pathname = url.parse(req.url).pathname; - const sane = Path.normalize(pathname).replace(/^(\.\.\/)+/, ""); + const pathname = parseURL(req.url).pathname; + const sane = normalize(pathname).replace(/^(\.\.\/)+/, ""); let path = `${this.root}${sane}`; //Path.join(__dirname, sane); fs.stat(path, (err, stats) => { @@ -60,7 +60,7 @@ module.exports = class Static { }} if (stats.isDirectory()) path += "/index.html"; - const ext = `${Path.extname(path)}`.toLowerCase(); + const ext = `${extname(path)}`.toLowerCase(); const stream = fs.createReadStream(path); stream.on("error", e => { console.log(e); |