Oak: Remove HTML extensions when serving files
Using Oak, how can I serve
home.html
as /home
(or /home/
). I'm aware that Context#send
exists but I'm not sure if it'll work with my use case.
Thanks in advance!2 Replies
The documentation does not provide a specific example of serving HTML files without the
.html
extension using Oak. However, you can achieve this by setting up your Oak routes to match the desired paths (like /home
or /home/
) and then use the ctx.send()
method to serve the corresponding HTML file.
Here's a general example:
In this example, a GET request to /home
will serve the home.html
file. Please replace "${Deno.cwd()}/path/to/your/html/files"
with the actual path to your HTML files.
Remember, this is a general advice and not explicitly stated in the documentation. Always test your code thoroughly to ensure it works as expected. 🦕I have a static file generator so I can't "predefined" routes