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:
parent
9d77455926
commit
18cca9b49e
1 changed files with 6 additions and 1 deletions
7
app.js
7
app.js
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue