Skip to content

Commit

Permalink
Fixes proxy error in NodeJS-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Hallbergs committed Jun 19, 2023
1 parent b7f3a2f commit 45565ae
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions new-backend/server/common/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,19 @@ built-it compression by setting the ENABLE_GZIP_COMPRESSION option to "true" in
);
}

this.setupGenericProxy();

this.setupSokigoProxy();

this.setupFmeProxy();

app.use(Express.json({ limit: process.env.REQUEST_LIMIT || "100kb" }));
app.use(
Express.urlencoded({
extended: true,
limit: process.env.REQUEST_LIMIT || "100kb",
})
);
app.use(Express.text({ limit: process.env.REQUEST_LIMIT || "100kb" }));
app.use(cookieParser(process.env.SESSION_SECRET));
// We have to make sure to add the json-parsers etc. after the proxies has been initiated.
// If they are added before, eventual payload trough the proxies will not be handled correctly.
this.setupProxies().then(() => {
app.use(Express.json({ limit: process.env.REQUEST_LIMIT || "100kb" }));
app.use(
Express.urlencoded({
extended: true,
limit: process.env.REQUEST_LIMIT || "100kb",
})
);
app.use(Express.text({ limit: process.env.REQUEST_LIMIT || "100kb" }));
app.use(cookieParser(process.env.SESSION_SECRET));
});

// Optionally, expose the Hajk client app directly under root (/)
process.env.EXPOSE_CLIENT === "true" &&
Expand Down Expand Up @@ -342,6 +340,14 @@ built-it compression by setting the ENABLE_GZIP_COMPRESSION option to "true" in
}
}

// Since we have to await the setup of the proxies (so that the JSON-parser etc. initiates after the proxies),
// we'll gather the all the setups here so they are easy to call.
async setupProxies() {
await this.setupSokigoProxy();
await this.setupFmeProxy();
this.setupGenericProxy();
}

async setupStaticDirs() {
const l = log4js.getLogger("hajk.static");

Expand Down

0 comments on commit 45565ae

Please sign in to comment.