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.
This commit is contained in:
fr33domlover 2019-06-14 17:36:31 +00:00
parent f8f3a31a8d
commit 698059763a
2 changed files with 18 additions and 12 deletions

View file

@ -193,12 +193,15 @@ instance Yesod App where
defaultCsrfHeaderName defaultCsrfHeaderName
defaultCsrfParamName defaultCsrfParamName
) )
. ( \ handler -> do . ( \ handler ->
host <- getsYesod $ appInstanceHost . appSettings if developmentMode
bs <- lookupHeaders hHost then handler
case bs of else do
[b] | b == encodeUtf8 host -> handler host <- getsYesod $ appInstanceHost . appSettings
_ -> invalidArgs [hostMismatch host bs] bs <- lookupHeaders hHost
case bs of
[b] | b == encodeUtf8 host -> handler
_ -> invalidArgs [hostMismatch host bs]
) )
. defaultYesodMiddleware . defaultYesodMiddleware
where where

View file

@ -164,14 +164,17 @@ data AppSettings = AppSettings
, appHighlightStyle :: Text , appHighlightStyle :: Text
} }
developmentMode :: Bool
developmentMode =
#if DEVELOPMENT
True
#else
False
#endif
instance FromJSON AppSettings where instance FromJSON AppSettings where
parseJSON = withObject "AppSettings" $ \ o -> do parseJSON = withObject "AppSettings" $ \ o -> do
let defaultDev = let defaultDev = developmentMode
#if DEVELOPMENT
True
#else
False
#endif
appStaticDir <- o .: "static-dir" appStaticDir <- o .: "static-dir"
appDatabaseConf <- o .: "database" appDatabaseConf <- o .: "database"
appMaxInstanceKeys <- o .:? "max-instance-keys" appMaxInstanceKeys <- o .:? "max-instance-keys"