Closed PiN73 closed 3 years ago
Discovering https://github.com/Jaguar-dart/jaguar/pull/137 I found that overriding mime type is possible this way for now
final server = Jaguar();
server.staticFiles('/static/*', 'static');
server.after.add((ctx) {
if (ctx.path.startsWith('/static/') && ctx.path.endsWith('.txt')) {
// for example, when serving .txt files, set mime type to text/html
ctx.response.headers.mimeType = MimeTypes.html;
}
});
await server.serve();
Anyway it would be good to know if responseProcessor
should be called by Jaguar in my case
@PiN73 responseProcessor
is only called when you return a result from the route handler. Static file handler does not return result, it instead updates the response
object.
Using after
is the right way to go for this.
@tejainece but then responseProcessor
parameter inside Jaguar@staticFiles
isn't consistent and shouldn't be present, should it?
I want to override response mime type when serving static files.
Tried to use
responseProcessor
but when the files are requested, my callback isn't called.
Is it a bug in Jaguar or am I doing something wrong?