Skip to content

Commit

Permalink
trying forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis Fedoruk-Betschki committed Jan 9, 2025
1 parent 9edadca commit e79e485
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const proxy = httpProxy.createProxyServer({
secure: false,
changeOrigin: true,
selfHandleResponse: true,
xfwd: true,
// followRedirects: true,
// proxyTimeout: 30000,
});
Expand Down Expand Up @@ -172,11 +173,14 @@ proxy.on('proxyReq', function (proxyReq, req, res, options) {
proxyReq.setHeader('x-forwarded-for', forwardedFor as string);
proxyReq.setHeader('x-real-ip', originalIp as string);
proxyReq.setHeader('x-forwarded-proto', 'https');
proxyReq.setHeader('x-forwarded-host', req.headers.host || '');

// Preserve original headers
// Object.keys(req.headers).forEach(function (key) {
// proxyReq.setHeader(key, req.headers[key] as string);
// });
Object.keys(req.headers).forEach(function (key) {
if (!['host', 'connection'].includes(key.toLowerCase())) {
proxyReq.setHeader(key, req.headers[key] as string);
}
});

// Send the raw body to Ghost for legitimate requests
if ((req as any).rawBody && (req as any).rawBody.length > 0) {
Expand Down Expand Up @@ -228,7 +232,8 @@ proxy.on('error', (err, req, res) => {
(res as Response).status(503).send(errorHtml);
});

app.use((req, res) => {
// Handle all routes
app.all('*', (req, res) => {
proxy.web(req, res, { target: GHOST_URL });
});

Expand Down

0 comments on commit e79e485

Please sign in to comment.