import { RequestHandler } from "express" ; import IBaseRequest from "../IBaseRequest" ; import getPathFromOriginalUrl from "./getPathFromOriginalUrl" ; export default function staticRoute ( options ) { return async ( req , res , next ) => { try { const hostnameHeader = options . hostnameHeader && options . hostnameHeader . toLowerCase ( ) ; const hostname = hostnameHeader && typeof req . headers [ hostnameHeader ] === "string" ? ( req . headers [ hostnameHeader ] as string ) : req . hostname ; const respondToEndpointRequest = req . makeUsecase ( "respondToEndpointRequest" ) ; const response = await respondToEndpointRequest . exec ( { hostname : hostname , path : getPathFromOriginalUrl ( req . originalUrl ) , } ) ; res . status ( response . statusCode ) . set ( response . headers ) . send ( response . body ) ; } catch ( err ) { next ( err ) ; } } ; }