Skip to content

Commit

Permalink
fetch works, needs test
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed May 14, 2024
1 parent bd61b9d commit e886be1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,23 @@ export function createApp(devJsonPath: string, opts: DevOptions): Express.Applic
}

function setupUrlGateway(gatewayUrl: string) {
// Setup express to redirect or proxy to a URL gateway
app.use((req, res, next) => {
if (req.path === "/") {
return next();
}
// Redirect or proxy to the URL
res.redirect(gatewayUrl + req.url); // Simple redirect, adjust if you need to proxy
});
fetch(gatewayUrl)
.then((response) => {
if (!response.ok) {
throw new Error('Failed to fetch gateway content');
}
return response.text();
})
.then((data) => {
const modifiedDist = handleReplacements(data, opts);
app.get("*", (_, res) => {
res.send(modifiedDist);
});
})
.catch((err) => {
log.error(err);
log.error("Failed to set up URL gateway.");
});
log.success("URL gateway setup successfully.");
}

Expand Down

0 comments on commit e886be1

Please sign in to comment.