fix(ssg): Error when ContentType is missing
fixes: https://github.com/honojs/hono/issues/2244
This sets the specification for the defaultContentType of SSG, which was implicitly set to text/plain until now.
However, as per the issue mentioned above, this may not be appropriate. Therefore, we have added the option defaultContentType. In normal settings, routes like c.redirect, which include no content-type, will result in an error.
If set, it will fallback to the specified value. One issue is that setting the DefaultContent-type to an arbitrary value like 'aaaa' results in an empty .html file being output. This is because the default value in determineExtension is .html, but there is room for discussion on what the specification should be regarding this issue.
Author should do the followings, if applicable
- [x] Add tests
- [x] Run tests
- [x]
yarn denoifyto generate files for Deno
@yusukebe @usualoma I would like to get your opinion on this specification.
I made it, but if we are going to solve the .html completion problem, it might not be much different from not providing a defaultContentType option and automatically making it an error.
Hi @watany-dev. Thank you!
I can't think of any situation where defaultContentType would be needed. I think it would be very very rare, if any, so instead of providing a defaultContentType option, I think we would be better to encourage to use afterResponseHook() for prepareing fallback.
Hey @watany-dev @usualoma !
I agree with @usualoma. I don't think defaultContentType is necessary. That's because he's right, the Content-Type is set in the Response in many cases.
However, as per the issue mentioned above, this may not be appropriate. Therefore, we have added the option defaultContentType. In normal settings, routes like c.redirect, which include no content-type, will result in an error.
Certainly the case for redirect responses must be considered, but it is a question of how to handle 301 and 302 status codes. We can discuss that in #2180.
close.
Ref: https://github.com/honojs/hono/issues/2284