Read static files from the correct directory

By default, paths in Node.js are resolved based upon the current
directory. This is problematic when the server is started from the home
directory or through systemd. This commit ensures static files are read
relative to app.js's path, instead of the current directory.
This commit is contained in:
CountBleck 2022-08-25 21:56:26 -07:00
parent 9d77455926
commit 18cca9b49e

7
app.js
View file

@ -1,5 +1,7 @@
import createBareServer from '@tomphttp/bare-server-node';
import http from 'http';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import nodeStatic from 'node-static';
import * as custombare from './static/customBare.mjs';
@ -9,7 +11,10 @@ const bareServer = createBareServer('/bare/', {
localAddress: undefined
});
const serve = new nodeStatic.Server('static/');
const serve = new nodeStatic.Server(join(
dirname(fileURLToPath(import.meta.url)),
'static/'
));
const server = http.createServer();