Closed mastoj closed 4 years ago
You can use the use_static
command in the application and provide that with a physical path where static files live?
@isaacabraham, sounds simple enough. But how do you go about serving an index.html
on /
?
There is Controller.file
helper function - https://github.com/SaturnFramework/Saturn/blob/master/src/Saturn/ControllerHelpers.fs#L42
I'd prefer doing a permanent redirect from /
to /index.html
, and if you were already serving static files at your root then that would do just fine. This is nice because the underlying static files middleware handles etag calculation, HEAD requests, everything for you: https://github.com/aspnet/AspNetCore/blob/master/src/Middleware/StaticFiles/src/StaticFileContext.cs#L298-L341
Ooh, I found a better, more supported way: add app.UseDefaultFiles()
before app.UseStaticFiles()
: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-3.0#serve-a-default-document
But the use_static
handler already sets app.UseDefaultFiles()
(see https://github.com/SaturnFramework/Saturn/blob/master/src/Saturn/Application.fs#L209), so it looks like it should work already?
I had some problems getting it to work when I cloned the repo and tried to run the ChannelSample
project. The app starts, but I can't reach any of the routes specified, this is even before me trying to modify them. It works perfectly fine when I create the project from the Saturn template.
My goal was to create a minimalistic client sample for the ChannelSample
to showcase how to connect to channels.
I'll open a separate issue on ☝️
@baronfel that's exactly why I put that into Saturn a year or so ago re: usedefaultfiles
:-)
I can’t find what the best way to serve a static abc.html file is in Saturn? Is it to use
Controller.text
and feed that the content of the file and then also set the content type header? Or is it something built in that I haven’t found where you just can point to the file?