dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
595 stars 50 forks source link

Add redirection helper for vite #1410

Open Jand42 opened 3 months ago

Jand42 commented 3 months ago

A debug-oriented middleware to use readable WebSharper outputs through vite:

            .Use(fun context (next: RequestDelegate) ->
                if context.Request.Path.StartsWithSegments("/Scripts") || context.Request.Path.StartsWithSegments("/@vite") then
                    let proxyRequest = context.Request.Path.Value
                    context.Response.Redirect($"http://localhost:5173{proxyRequest}")
                    Task.CompletedTask
                else
                    next.Invoke(context)
            )

Adding this as .UseWebSharperScriptRedirect() which can take redirect url from appsettings.Development.json (or possibly directly from an optional arg), but defaults to the one above (default for vite)

granicz commented 3 months ago

This would be a good time to add support for a webpack dev server in the config file too. Something like:

debug.server=vite|webpack, and debug.rewriteUrl=...