Skip to content

Commit

Permalink
fix: detect scheme served
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBLT committed Mar 9, 2024
1 parent cab44ea commit d0c0ec4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/@hec.js/api/lib/src/routing/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export function serveBy(fetch) {
* @param { import('http').ServerResponse } res
*/
return (req, res) => {
const scheme = req.headers['x-forwarded-proto'] ?? (
req.headers['cf-visitor']?.includes('https') ? 'https' : null
) ?? 'http';

fetch(
new Request(`http://${req.headers.host}${req.url}`, {
new Request(`${ scheme }://${ req.headers.host }${ req.url }`, {
method: req.method,
duplex: 'half',
// @ts-ignore
Expand All @@ -32,8 +36,10 @@ export function serveBy(fetch) {
res.statusCode = response.status;

for (const e of response.headers.entries()) {
res.setHeader(e[0], e[1]);
res.appendHeader(e[0], e[1]);
}

res.flushHeaders();

if (response.body) {
// @ts-ignore
Expand Down

0 comments on commit d0c0ec4

Please sign in to comment.