Fork me on GitHub
#duct
<
2018-07-09
>
tobiasq13:07:08

Hi, I'm using duct to serve a fulcro webapp and I want to alias "/" as "/index.html" so it's served as a static route. I've tried using the following configuration keys:

:duct.middleware.web/route-aliases {"/" "/index.html"}
:duct.core/handler {:middleware [#ig/ref :duct.middleware.web/route-aliases]}
but not having any luck getting
http :3000
to serve the same as
http :3000/index.html

weavejester13:07:04

I can’t see anything obviously wrong with that. What does (pprint (:duct.core/handler config)) look like?

tobiasq13:07:47

{:middleware [#ig/ref :duct.middleware.web/route-aliases
              #ig/ref :duct.middleware.web/not-found
              #ig/ref :duct.middleware.web/webjars
              #ig/ref :duct.middleware.web/defaults
              #ig/ref :duct.middleware.web/log-requests
              #ig/ref :duct.middleware.web/log-errors
              #ig/ref :duct.middleware.web/stacktrace],
 :router #ig/ref :duct/router}
is the output

tobiasq13:07:42

and

(pprint (:duct.middleware.web/route-aliases config))
is
{"/" "/index.html"}
@weavejester

weavejester13:07:36

Hm. I don’t see anything wrong with that, either…

weavejester13:07:47

What happens when you go to “/”?

weavejester14:07:11

Oh, actually, I do see the problem.

weavejester14:07:04

If the index page is static, then it will be served by wrap-resource in the defaults middleware before the route-aliases are reached.

weavejester14:07:09

So:

{:middleware [#ig/ref :duct.middleware.web/not-found
              #ig/ref :duct.middleware.web/webjars
              #ig/ref :duct.middleware.web/defaults
              #ig/ref :duct.middleware.web/route-aliases]}

weavejester14:07:51

By putting the references in directly, you can explicitly specify the order.

tobiasq14:07:28

@weavejester Thanks! just tried that and it works perfectly 🙂

weavejester14:07:06

No problem! I’ve been thinking about a more sophisticated way of ordering middleware, but it’s always a tradeoff.