Type | Ts.Ed Version | Typescript Version | Node Version
---|---|--|---
Bug | v3.10.2 | v2.7.2 | v8.11.1
Hi, Romakita
I have a problem getting serveStatic config to work as I always receive a 404 response when requesting a static file. Here is my config:
/home/mouneer/ts-server/src/app.ts
@ServerSettings({
serveStatic: {
['assets']: path.resolve(__dirname, '../assets'),
},
})
ts-server
β ...
ββββsrc
β β app.ts
β ...
ββββdist
β β app.js
β ...
ββββassets
β β ...
β ββββprofile
β β avatar.png
[2018-07-04T16:12:55.404] [INFO ] [TSED] - settings.serveStatic => { '/assets': '/home/mouneer/ts-server/assets' }
[2018-07-04T16:16:41.356] [DEBUG] [TSED] - {
"event": "start",
"reqId": "3",
"method": "GET",
"url": "/assets/profile/avatar.png",
"duration": 0,
"headers": {
"host": "localhost:3020",
"connection": "close",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cookie": "connect.sid=s%3APwaFQ8_7wVBQDuNVh64lf0KWD0hA7W2Z.ZFw7AzNuza4NAKU08O9hH%2FDV%2FUCpA8N2Va94Zl8v1Uw"
},
"body": {},
"query": {},
"params": {}
}
[2018-07-04T16:16:41.356] [DEBUG] [TSED] - {
"type": "middleware",
"target": "LogIncomingRequestMiddleware",
"methodName": "use",
"injectable": true,
"event": "invoke.end",
"reqId": "3",
"method": "GET",
"url": "/assets/profile/avatar.png",
"duration": 0,
"headers": {
"host": "localhost:3020",
"connection": "close",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cookie": "connect.sid=s%3APwaFQ8_7wVBQDuNVh64lf0KWD0hA7W2Z.ZFw7AzNuza4NAKU08O9hH%2FDV%2FUCpA8N2Va94Zl8v1Uw"
},
"body": {},
"query": {},
"params": {}
}
[2018-07-04T16:16:41.356] [INFO ] [TSED] - {
"status": 404,
"reqId": "3",
"method": "GET",
"url": "/assets/profile/avatar.png",
"duration": 0
}
[2018-07-04T16:16:41.356] [DEBUG] [TSED] - {
"status": 404,
"reqId": "3",
"method": "GET",
"url": "/assets/profile/avatar.png",
"duration": 0,
"headers": {
"host": "localhost:3020",
"connection": "close",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cookie": "connect.sid=s%3APwaFQ8_7wVBQDuNVh64lf0KWD0hA7W2Z.ZFw7AzNuza4NAKU08O9hH%2FDV%2FUCpA8N2Va94Zl8v1Uw"
},
"body": {},
"query": {},
"params": {}
}
{
"res": {
"statusCode": 404
},
"req": {
"url": "/assets/profile/avatar.png",
"headers": {
"host": "localhost:3020",
"connection": "close",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cookie": "connect.sid=s%3APwaFQ8_7wVBQDuNVh64lf0KWD0hA7W2Z.ZFw7AzNuza4NAKU08O9hH%2FDV%2FUCpA8N2Va94Zl8v1Uw"
},
"method": "GET",
"httpVersion": "1.0",
"originalUrl": "/assets/profile/avatar.png",
"query": {}
},
"responseTime": 1,
"level": "info",
"message": "HTTP GET /assets/profile/avatar.png"
}
Thanks, Romakita :)
Ok found. Just replace this config ['assets']: path.resolve(__dirname, '../assets'),
by '/assets': path.resolve(__dirname, '../assets'),
It will works :)
Romain
Sorry, Romakita. It's my fault. I'm already configuring it with the slash / and it's also clear from the submitted log
[2018-07-04T16:12:55.404] [INFO ] [TSED] - settings.serveStatic => { '/assets': '/home/mouneer/ts-server/assets' }
So what do u think could be the reason for the 404?
Currently the configuration works with the latest version. I'll tried with the version 3, to reproduce it.
Ok have you correctly imported import "ts-express-decorators/servestatic" in your app.ts ?
Because your serve static configuration works with v3 :)
Great! Importing import 'ts-express-decorators/servestatic'; fixes the problem.
Thanks, Romain :)
@Romakita This issue still exists in version : 5.31.1
@dlinx
Can create a new issue please and send your config and more details. Please. This issue is obsolete.