             ;; and metadata is merged onto that.
             arg-resolvers (merge arg-resolvers (:arg-resolvers metadata))
             handler (cond->
-                      {:middleware-key middleware-key
-                       :route-params   route-params
-                       :verb-fn-sym    verb-fn-sym
-                       :arglist        arglist
-                       :arg-resolvers  arg-resolvers
-                       :metadata       metadata}
+                      {:middleware    endpoint-middleware
+                       :route-params  route-params
+                       :verb-fn-sym   verb-fn-sym
+                       :arglist       arglist
+                       :arg-resolvers arg-resolvers
+                       :metadata      metadata}
                       context
                       (assoc :context (string/join "/" (cons "" context))))
             handlers' (assoc handlers handler-key handler)]
-        [routes' handlers' middleware' namespaces-metadata']))))
+        [routes' handlers' namespaces-metadata']))))
 
 (declare default-arg-resolver-factories default-arg-resolvers)
 


(defn- build-dispatch-map
  "Returns a dispatch-map for use with map-traversal-dispatcher."
  [{:keys [routes handlers middleware]}
   {:keys [async? arg-resolvers sync-wrapper]}]
  (reduce (fn [dispatch-map [[method pathvec] handler-key]]
            (t/track #(format "Compiling handler for `%s'."
                              (get-in handlers [handler-key :verb-fn-sym]))
                     (let [{:keys           [middleware-key route-params
                                             verb-fn-sym arglist
                                             metadata context]
                            extra-resolvers :arg-resolvers}

                                                  extra-resolvers))
                                              (set route-params)
                                              arglist)

                           ;; middleware may return nil, so:

