2

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?

user2649762
  • 541
  • 3
  • 13
  • 2
    The most probable explanation is that the current working directory where the program is run is not the one that contains the `static` subdirectory with your static files. It looks like you're using Stack. Can you describe your project directory structure and how you're building and running the program (e.g., using an IDE of some kind, from the command line, etc.)? If you add a `print =<< getCurrentDirectory` at the beginning of `startApp`, are you in the directory you expect? – K. A. Buhr Dec 13 '20 at 22:46
  • Yes, this was exactly the problem. I ran it from a different directory. Thank you. – user2649762 Dec 14 '20 at 12:15

0 Answers0