From 698059763a4452c27448da3a2103fee2e3f9e6c5 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Fri, 14 Jun 2019 17:36:31 +0000 Subject: [PATCH] When building with dev flag, disable the approot host check middleware This allows to browse via e.g. localhost:3000 even if the instance host is something else and the rendered URLs don't have a port number. It still makes many things impossible or inconvenient, but at least you can launch Vervis locally for development and see pages. Right now even CSS doesn't work because of the URLs not matching the actual localhost:3000 access. Maybe gradually I'll figure it out. --- src/Vervis/Foundation.hs | 15 +++++++++------ src/Vervis/Settings.hs | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index bb656dd..4e7bad9 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -193,12 +193,15 @@ instance Yesod App where defaultCsrfHeaderName defaultCsrfParamName ) - . ( \ handler -> do - host <- getsYesod $ appInstanceHost . appSettings - bs <- lookupHeaders hHost - case bs of - [b] | b == encodeUtf8 host -> handler - _ -> invalidArgs [hostMismatch host bs] + . ( \ handler -> + if developmentMode + then handler + else do + host <- getsYesod $ appInstanceHost . appSettings + bs <- lookupHeaders hHost + case bs of + [b] | b == encodeUtf8 host -> handler + _ -> invalidArgs [hostMismatch host bs] ) . defaultYesodMiddleware where diff --git a/src/Vervis/Settings.hs b/src/Vervis/Settings.hs index 55740e5..a2882ca 100644 --- a/src/Vervis/Settings.hs +++ b/src/Vervis/Settings.hs @@ -164,14 +164,17 @@ data AppSettings = AppSettings , appHighlightStyle :: Text } +developmentMode :: Bool +developmentMode = +#if DEVELOPMENT + True +#else + False +#endif + instance FromJSON AppSettings where parseJSON = withObject "AppSettings" $ \ o -> do - let defaultDev = -#if DEVELOPMENT - True -#else - False -#endif + let defaultDev = developmentMode appStaticDir <- o .: "static-dir" appDatabaseConf <- o .: "database" appMaxInstanceKeys <- o .:? "max-instance-keys"