Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE: #97 - Partial responses Azure Container Apps #98

Open
wants to merge 2 commits into
base: govuk/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bugs

- [#97](https://github.com/DFE-Digital/polis-whitelabel/issues/97) Only partial responses returned when deployed to Azure Container App
- [#91](https://github.com/DFE-Digital/polis-whitelabel/issues/91) Allow no email transport to be configured without crash
- [#87](https://github.com/DFE-Digital/polis-whitelabel/issues/85) Client report no longer hardcoded to pol.is domain
- [#85](https://github.com/DFE-Digital/polis-whitelabel/issues/85) Fix local Docker Compose script
Expand Down
6 changes: 6 additions & 0 deletions deploy/docker/reverse-proxy-config/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ server {
add_header X-Cache-Status $upstream_cache_status;
proxy_buffering on;

# Envoy (used in Azure Container Apps) requires HTTP 1.1 and also does chunked transfer
# so we need to make sure that the connection header isn't set to default of 'close'
proxy_http_version 1.1;
proxy_set_header "Connection" "";


# A health check endpoint
location = /health {
return 204;
Expand Down
8 changes: 4 additions & 4 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/connect-timeout": "^0.0.34",
"@types/express": "^4.17.11",
"@types/fb": "^0.0.28",
"@types/http-proxy": "^1.17.5",
"@types/http-proxy": "^1.17.14",
"@types/lru-cache": "^5.1.0",
"@types/node": "^14.14.39",
"@types/nodemailer": "^6.4.1",
Expand Down
8 changes: 1 addition & 7 deletions server/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6806,13 +6806,7 @@ let handle_GET_conditionalIndexFetcher = (function () {

function handle_GET_localFile_dev_only(
req: Request,
res: {
writeHead: (
arg0: number,
arg1?: { "Content-Type": string } | undefined
) => void;
end: (arg0?: undefined, arg1?: string) => void;
}
res: Response
) {
const filenameParts = String(req.path).split("/");
filenameParts.shift();
Expand Down
17 changes: 12 additions & 5 deletions server/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

import akismetLib from "akismet";
import http from 'http';
import https from 'https';
import async from "async";
import badwords from "badwords/object";
import crypto from "crypto";
Expand Down Expand Up @@ -5752,7 +5754,7 @@ function makeFileFetcher(
}
let url = "http://" + hostname + ":" + port + path;
console.log("info", "fetch file from " + url);
let fsReq = request.get(url)
let fsReq = request.get(url, { forever: true })

fsReq
.on("error", function (err: any) {
Expand Down Expand Up @@ -6119,11 +6121,10 @@ function browserSupportsPushState(req: { headers?: { [x: string]: string } }) {
return !/MSIE [23456789]/.test(req?.headers?.["user-agent"] || "");
}

// 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009)
// @ts-ignore
let routingProxy = new httpProxy.createProxyServer();

function proxy(req: Request, res: any) {
let routingProxy = httpProxy.createProxyServer();

function proxy(req: Request, res: Response) {
let hostname = buildStaticHostname(req, res);
if (!hostname) {
let host = req?.headers?.host || "";
Expand All @@ -6148,7 +6149,13 @@ function proxy(req: Request, res: any) {
let port = process.env.STATIC_FILES_PORT;
// set the host header too, since S3 will look at that (or the routing proxy will patch up the request.. not sure which)
if (req && req.headers && req.headers.host) req.headers.host = hostname;

const isHttps = port === '443'

routingProxy.web(req, res, {
agent: isHttps
? new https.Agent({ keepAlive: true })
: new http.Agent({ keepAlive: true }),
target: {
host: hostname,
port: port,
Expand Down