module Hack.Contrib.Static where

import Hack
import Hack.Response
import Hack.Utils
import Hack.Contrib.File (file)

import MPSUTF8
import Prelude hiding ((.), (^), (>), (+))
import Data.Maybe
import List (find, isPrefixOf)

program = "Static"

static :: Maybe String -> [String] -> MiddleWare
static root urls app = \env -> do
  let my_urls = if urls.null then ["/favicon.ico"] else urls

  let path = env.path_info .url2unicode

  let can_serve = my_urls.find ( `isPrefixOf` path ) .isJust
  
  if can_serve
    then file root app env
    else app env