It is quite often that one needs an empty sitelet to start from. Usually, I perform the following steps to get there (note how the project names tranfers as namespace in the code files):
-
dotnet new -lang f# -n MyProject
-
dotnet add package WebSharper and dotnet add package WebSharper.AspNetCore
-
Add a simple Site.fs as the first code file in the project, with:
module Site
open WebSharper
open WebSharper.Sitelets
[<Website>]
let Main = Application.Text (fun ctx -> "Hello World!")
-
Merge Program.fs and Startup.fs into a single combined Startup.fs:
namespace MyProject
open System
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open WebSharper.AspNetCore
type Startup() =
member this.ConfigureServices(services: IServiceCollection) =
services.AddSitelet(Site.Main)
.AddAuthentication("WebSharper")
.AddCookie("WebSharper", fun options -> ())
|> ignore
member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) =
if env.IsDevelopment() then app.UseDeveloperExceptionPage() |> ignore
app.UseAuthentication()
.UseStaticFiles()
.UseWebSharper()
.Run(fun context ->
context.Response.StatusCode <- 404
context.Response.WriteAsync("Page not found"))
module Program =
let BuildWebHost args =
WebHost
.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build()
[<EntryPoint>]
let main args =
BuildWebHost(args).Run()
0
I believe it would be a benefit to make this a dedicated template, say as websharper-min.
It is quite often that one needs an empty sitelet to start from. Usually, I perform the following steps to get there (note how the project names tranfers as namespace in the code files):
dotnet new -lang f# -n MyProjectdotnet add package WebSharperanddotnet add package WebSharper.AspNetCoreAdd a simple
Site.fsas the first code file in the project, with:Merge
Program.fsandStartup.fsinto a single combinedStartup.fs:I believe it would be a benefit to make this a dedicated template, say as
websharper-min.