only rewrite routes if LOCALHOST env variable is unset

This commit is contained in:
Sarah Vaupel 2023-08-06 18:59:06 +00:00
parent 6bb3dbaef7
commit b8e947fea4

View File

@ -39,6 +39,8 @@ import Data.Void
import Network.URI import Network.URI
import System.Environment (lookupEnv)
config :: Configuration config :: Configuration
config = config =
defaultConfiguration defaultConfiguration
@ -65,7 +67,8 @@ unwrapped :: Snapshot
unwrapped = "unwrapped" unwrapped = "unwrapped"
main :: IO () main :: IO ()
main = hakyllWith config $ do main =
lookupEnv "LOCALHOST" >>= \((Nothing /=) -> localhost) -> hakyllWith config $ do
frontendManifest <- frontendManifest <-
preprocess $ preprocess $
Yaml.decodeFileThrow @_ @(Map String [FilePath]) "frontend/dist/.manifest.yaml" Yaml.decodeFileThrow @_ @(Map String [FilePath]) "frontend/dist/.manifest.yaml"
@ -88,6 +91,9 @@ main = hakyllWith config $ do
forM resources $ load . fromFilePath . ("frontend/dist" </>) . dropDrive forM resources $ load . fromFilePath . ("frontend/dist" </>) . dropDrive
netlifyRedirects <- netlifyRedirects <-
if localhost
then return []
else
preprocess . handleIf isDoesNotExistError (const $ return []) $ preprocess . handleIf isDoesNotExistError (const $ return []) $
let pNetlify :: ParsecT Void Lazy.Text m [(FilePath, FilePath)] let pNetlify :: ParsecT Void Lazy.Text m [(FilePath, FilePath)]
pNetlify = catMaybes <$> MP.sepBy (MP.space *> pLine <* MP.hspace) pEOL <* MP.eof pNetlify = catMaybes <$> MP.sepBy (MP.space *> pLine <* MP.hspace) pEOL <* MP.eof