-
-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Describe the bug
Setting the VOLUMES_CONFIG environment variable to any relative path leads to the server returning Error 500 for any route that is not either
- the index ('' or '/')
- a static frontend asset (e.g. '/logo.svg')
- an API route
To Reproduce
Steps to reproduce the behavior:
- Clone this repository.
- Copy
.dev.envto.env. - Set
VOLUMES_CONFIGto any relative path (can also leave it as the default./.local/config). - Start the server, register & login in the WebUI.
- Access any path that is not one of the aforementioned, e.g. '/library'.
It is important that you do not get there using the router of the frontend (there has to be made a request to the server), so e.g. access it via the URL bar directly or force-reload the page. - Observe the error JSON response with code 500 and the error log
error: ┏ Unhandled TypeError occurred. +30s
error: ┃ [ 1] [[
error: ┃ [ 2] undefined
error: ┃ [ 3] ]]
error: ┃ [ 4] {
error: ┃ [ 5] context: 'LoggingExceptionFilter',
error: ┃ [ 6] error: TypeError: path must be absolute or specify root to res.sendFile
error: ┃ [ 7] at ServerResponse.sendFile ([...]/node_modules/.pnpm/express@5.1.0/node_modules/express/lib/response.js:398:11)
error: ┃ [ 8] at renderFn ([...]/node_modules/.pnpm/@nestjs+serve-static@5.0.4_@nestjs+common@11.1.9_class-transformer@0.5.1_class-validato_2c1fbf4e08d8af99a57535dcfd27ed9a/node_modules/@nestjs/serve-static/dist/loaders/express.loader.js:67:25)
error: ┃ [ 9] at Layer.handleRequest ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/lib/layer.js:152:17)
error: ┃ [10] at next ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/lib/route.js:157:13)
error: ┃ [11] at Route.dispatch ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/lib/route.js:117:3)
error: ┃ [12] at handle ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/index.js:435:11)
error: ┃ [13] at Layer.handleRequest ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/lib/layer.js:152:17)
error: ┃ [14] at [...]/node_modules/.pnpm/router@2.2.0/node_modules/router/index.js:295:15
error: ┃ [15] at param ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/index.js:600:14)
error: ┃ [16] at param ([...]/node_modules/.pnpm/router@2.2.0/node_modules/router/index.js:610:14),
error: ┃ [17] path: '/library',
error: ┃ [18] timestamp: '...'
error: ┗ [19] }Expected behavior
The server should serve the frontend index.html with an appropriate code, i.e. <500.
Additional context
The issue seems to stem from the ServeStaticModule.
Setting rootPath: resolve(join(configuration.VOLUMES.CONFIG, "frontend", "dist")) seems to avoid the issue, as it is evaluated to an absolute path then.
I looked into the NestJS documentation but did not find any mention of this restriction, however in all examples I have seen an absolute path is used (e.g. using joins with __dirname or process.cwd()).
Thus I took a look at the implementation of the module and from what I can tell the issue seems to stem from there, in that no resolveing or setting of the root parameter happens in this line. Because of that the indexFilePath variable evaluates to a relative path, which res.sendFile cannot handle without a root option, thus the error (sendFile throws the TypeError before it calls the error callback).
As the docker build sets the VOLUMES_CONFIG to the absolute path /config by default, this issue is not observed there. The error is also not observed for the aforementioned paths, as those are handled by the GameVault servers' other controllers or express.static before the static handler sends index.html in the renderFn.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status