Skip to content

Commit

Permalink
💫 exposed redirectPatternToPath method (for testing) #7
Browse files Browse the repository at this point in the history
  • Loading branch information
8eecf0d2 committed Oct 20, 2018
1 parent b3ac85c commit 43c6ae6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ export class Server {
const placeholderOptions = Server.placeholderOptions(redirect);
this.express.all(redirect.from, Server.redirectHeadersMiddleware(redirect), Server.placeholderParamsMiddleware(), (request, response, next) => {

return response.status(redirect.status).redirect(placeholderOptions.pattern.stringify(request.params));
return response.status(redirect.status).redirect(Server.redirectPatternToPath(placeholderOptions.pattern, request.params));
})
}

private handleRewrite (redirect: Netlify.Redirect): void {
const placeholderOptions = Server.placeholderOptions(redirect);
this.express.all(redirect.from, Server.redirectHeadersMiddleware(redirect), Server.placeholderParamsMiddleware(), (request, response, next) => {

return response.status(redirect.status).sendFile(path.join(this.paths.static, placeholderOptions.pattern.stringify(request.params)));
return response.status(redirect.status).sendFile(path.join(this.paths.static, Server.redirectPatternToPath(placeholderOptions.pattern, request.params)));
});
}

Expand All @@ -124,7 +124,7 @@ export class Server {
this.express.all(redirect.from, Server.redirectHeadersMiddleware(redirect), Server.placeholderParamsMiddleware(), (request, response, next) => {

return expressHttpProxy(placeholderOptions.url.origin, {
proxyReqPathResolver: (proxyRequest: express.Request) => placeholderOptions.pattern.stringify(request.params),
proxyReqPathResolver: (proxyRequest: express.Request) => Server.redirectPatternToPath(placeholderOptions.pattern, request.params),
})(request, response, next);
});
}
Expand Down Expand Up @@ -168,6 +168,9 @@ export class Server {
}
}

private static redirectPatternToPath (pattern: UrlPattern, params: { [key: string]: string }): string {
return pattern.stringify(params);
}

/**
Lambda Router
Expand Down

0 comments on commit 43c6ae6

Please sign in to comment.