Suave serves Vue files

- Only send the 404 for /api routes; otherwise, serve files from
wwwroot, and send index.html if the path doesn't exist, so Vue can
handle it
- Minor build file tweaks
This commit is contained in:
Daniel J. Summers 2017-09-14 07:01:28 -05:00
parent 2ed01b8d5d
commit a10e4ded48
3 changed files with 14 additions and 11 deletions

View File

@ -2,7 +2,7 @@
open Fake open Fake
open System open System
let buildDir = "./build/" let buildDir = "build"
/// Path to the Vue app /// Path to the Vue app
let appPath = "src" @@ "app" let appPath = "src" @@ "app"
@ -39,7 +39,7 @@ Target "BuildApi" (fun _ ->
Target "Publish" (fun _ -> Target "Publish" (fun _ ->
ExecProcess (fun info -> ExecProcess (fun info ->
info.FileName <- "dotnet" info.FileName <- "dotnet"
info.Arguments <- """publish -o ..\..\build""" info.Arguments <- sprintf "publish -o %s" (".." @@ ".." @@ buildDir)
info.WorkingDirectory <- apiPath) TimeSpan.MaxValue info.WorkingDirectory <- apiPath) TimeSpan.MaxValue
|> ignore |> ignore
) )

View File

@ -149,7 +149,6 @@ module Route =
/// /api/journal ~ All active prayer requests for a user /// /api/journal ~ All active prayer requests for a user
let journal = "/api/journal" let journal = "/api/journal"
/// All WebParts that compose the public API /// All WebParts that compose the public API
module WebParts = module WebParts =
@ -173,12 +172,20 @@ module WebParts =
let reqs = Data.Requests.allForUser (defaultArg (read ctx "user") "") dataCtx let reqs = Data.Requests.allForUser (defaultArg (read ctx "user") "") dataCtx
JSON reqs) JSON reqs)
/// API-specific routes
let apiRoutes =
choose [
GET >=> path Route.journal >=> viewJournal
errorJSON HttpCode.HTTP_404 "Page not found"
]
/// Suave application /// Suave application
let app = let app =
Auth.loggedOn Auth.loggedOn
>=> choose [ >=> choose [
GET >=> path Route.journal >=> viewJournal path "/api" >=> apiRoutes
errorJSON HttpCode.HTTP_404 "Page not found" Files.browseHome
Files.browseFileHome "index.html"
] ]
[<EntryPoint>] [<EntryPoint>]

View File

@ -14,12 +14,8 @@
<Compile Include="Migrations/20170104023341_InitialDb.fs" /> <Compile Include="Migrations/20170104023341_InitialDb.fs" />
<Compile Include="Migrations/DataContextModelSnapshot.fs" /> <Compile Include="Migrations/DataContextModelSnapshot.fs" />
<Compile Include="App.fs" /> <Compile Include="App.fs" />
<Content Update="appsettings.json"> <None Include="appsettings.json" CopyToOutputDirectory="Always" />
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <None Include="wwwroot/**" CopyToOutputDirectory="Always" />
</Content>
<Content Update="wwwroot/**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.2.3" /> <PackageReference Include="FSharp.Core" Version="4.2.3" />