Can't make Servant serve static files

213 views Asked by At

Here's the entire code of the app:

{-# LANGUAGE DataKinds       #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators   #-}
module Lib
    ( startApp
    , app
    ) where

import Data.Aeson
import Data.Aeson.TH
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
import System.Environment

type API = "static" :> Raw


startApp :: IO ()
startApp = do
  tryPort <- lookupEnv "PORT"
  let port = (case tryPort of 
              Nothing -> "8080"
              Just a  -> a)
  run (read port) app

app :: Application
app = serve api server

api :: Proxy API
api = Proxy

server :: Server API
server = serveDirectoryWebApp "static/"

The "static" directory exists and contains a single file named "1.png". However, if I request "localhost:8080/static/1.png", the server just returns a 404. What could be the issue here?

0

There are 0 answers