diff --git a/Dockerfile b/Dockerfile index cdc8bad..bbce34e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,12 +10,11 @@ RUN mkdir -p /build && date -u '+%Y-%m-%d %H:%M UTC' > /build/build-time ADD build/sis-server /usr/local/bin/sis-server RUN chmod +x /usr/local/bin/sis-server -# Frontend static files are served separately (e.g. nginx, CDN, or -# a simple static file server). In development, use `npx serve`. +# Frontend SPA static files, served by sis-server via --static-dir. ADD frontend/dist /usr/local/share/sis/static ENTRYPOINT ["/usr/bin/tini", "-s", "--"] EXPOSE 8080 -CMD ["/usr/local/bin/sis-server", "--port", "8080"] +CMD ["/usr/local/bin/sis-server", "--port", "8080", "--static-dir", "/usr/local/share/sis/static"] diff --git a/app/Main.hs b/app/Main.hs index e937877..f842f72 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,7 +2,7 @@ {- | Entry point for the Sis chore tracker server. -Starts a Warp HTTP server and serves the JSON API. +Starts a Warp HTTP server, serves the JSON API and the SPA frontend. -} module Main (main) where @@ -14,6 +14,7 @@ import Sis.Server qualified as Sis data Options = Options { optPort :: Int + , optStaticDir :: FilePath } optionsParser :: Opt.Parser Options @@ -28,26 +29,36 @@ optionsParser = <> Opt.value 8080 <> Opt.showDefault ) + <*> Opt.strOption + ( Opt.long "static-dir" + <> Opt.metavar "DIR" + <> Opt.help "Directory containing the SPA frontend static files" + <> Opt.value "frontend/dist" + <> Opt.showDefault + ) main :: IO () main = do - opts <- Opt.execParser $ - Opt.info (optionsParser Opt.<**> Opt.helper) $ - Opt.fullDesc - <> Opt.progDesc "Sis — shared household chore tracker" - <> Opt.header "sis-server" + opts <- + Opt.execParser $ + Opt.info (optionsParser Opt.<**> Opt.helper) $ + Opt.fullDesc + <> Opt.progDesc "Sis — shared household chore tracker" + <> Opt.header "sis-server" -- Install a SIGTERM handler so Docker stop works cleanly. - _ <- Signals.installHandler - Signals.sigTERM - (Signals.Catch (putStrLn "[sis] shutting down")) - Nothing + _ <- + Signals.installHandler + Signals.sigTERM + (Signals.Catch (putStrLn "[sis] shutting down")) + Nothing - let waiApp = Sis.app + let waiApp = Sis.app (optStaticDir opts) let settings = - Warp.setPort (optPort opts) - $ Warp.setBeforeMainLoop (putStrLn $ "[sis] listening on port " ++ show (optPort opts)) - Warp.defaultSettings + Warp.setPort (optPort opts) $ + Warp.setBeforeMainLoop + (putStrLn $ "[sis] listening on port " ++ show (optPort opts)) + Warp.defaultSettings Warp.runSettings settings waiApp diff --git a/frontend/index.html b/frontend/index.html index e6e4e35..80410d1 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -6,9 +6,16 @@