Skip to content

Commit ff9a53b

Browse files
authored
Merge pull request #32 from gristlabs/jordigh/https-external
https: do not redirect to port 443 when HTTPS=external
2 parents ead1220 + 525c6bb commit ff9a53b

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

.github/test.sh

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,43 @@ IMAGE=gristlabs/grist-omnibus
99
TEAM=cool-beans
1010
PORT=9998
1111

12-
mkdir -p /tmp/omnibus-test
13-
docker run --rm --name grist \
14-
-e URL=http://localhost:$PORT \
15-
-v /tmp/omnibus-test:/persist \
16-
17-
-e PASSWORD=topsecret \
18-
-e TEAM=$TEAM \
19-
-p $PORT:80 \
20-
-d $IMAGE
21-
2212
function finish {
23-
docker logs grist || echo no logs
24-
docker kill grist > /dev/null
13+
HTTPS=$1
14+
docker logs grist$HTTPS || echo no logs
15+
docker kill grist$HTTPS > /dev/null
2516
}
2617
trap finish EXIT
2718

28-
for ct in $(seq 1 20); do
29-
echo "Check $ct"
30-
check="$(curl http://localhost:$PORT/api/orgs || echo fail)"
31-
if [[ "$check" = "[]" ]]; then
32-
echo Grist is responsive
33-
exit 0
34-
fi
35-
sleep 1
36-
done
37-
38-
echo "Grist did not respond"
39-
exit 1
19+
20+
function run_test() {
21+
HTTPS=$1
22+
docker run --rm --name grist$HTTPS \
23+
-e HTTPS=$HTTPS \
24+
-e URL=http://localhost:$PORT \
25+
-v /tmp/omnibus-test:/persist \
26+
27+
-e PASSWORD=topsecret \
28+
-e TEAM=$TEAM \
29+
-p $PORT:80 \
30+
-d $IMAGE
31+
32+
for ct in $(seq 1 20); do
33+
echo "Check $ct"
34+
check="$(curl http://localhost:$PORT/api/orgs || echo fail)"
35+
if [[ "$check" = "[]" ]]; then
36+
echo Grist is responsive with "HTTPS=$HTTPS"
37+
return
38+
fi
39+
sleep 1
40+
done
41+
42+
echo "Grist did not respond"
43+
exit 1
44+
}
45+
46+
mkdir -p /tmp/omnibus-test
47+
48+
run_test external
49+
finish external
50+
51+
run_test

run.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function main() {
2929

3030
await sleep(1000);
3131
log.info('I think everything has started up now');
32-
const ports = process.env.HTTPS ? '80/443' : '80';
32+
const ports = ['manual', 'auto'].includes(process.env.HTTPS) ? '80/443' : '80';
3333
log.info(`Listening internally on ${ports}, externally at ${process.env.URL}`);
3434
}
3535

@@ -63,14 +63,14 @@ function startGrist() {
6363
function startTraefik() {
6464
const flags = [];
6565
flags.push("--providers.file.filename=/settings/traefik.yaml");
66-
flags.push("--entryPoints.web.address=:80")
66+
flags.push("--entryPoints.web.address=:80");
6767

6868
if (process.env.HTTPS === 'auto') {
6969
flags.push(`--certificatesResolvers.letsencrypt.acme.email=${process.env.EMAIL}`)
7070
flags.push("--certificatesResolvers.letsencrypt.acme.storage=/persist/acme.json")
7171
flags.push("--certificatesResolvers.letsencrypt.acme.tlschallenge=true")
7272
}
73-
if (process.env.HTTPS) {
73+
if (['auto', 'manual'].includes(process.env.HTTPS)) {
7474
flags.push("--entrypoints.websecure.address=:443")
7575
// Redirect http -> https
7676
// See: https://doc.traefik.io/traefik/routing/entrypoints/#redirection
@@ -266,6 +266,12 @@ function prepareCertificateSettings() {
266266
if (!['auto', 'external', 'manual'].includes(https)) {
267267
throw new Error(`HTTPS environment variable must be set to: auto, external, or manual.`);
268268
}
269+
// If there is external HTTPS, something else will be in charge of
270+
// setting it up, so don't do it ourselves.
271+
if (https === 'external') {
272+
return;
273+
}
274+
269275
const tls = (https === 'auto') ? '{ certResolver: letsencrypt }' :
270276
(https === 'manual') ? 'true' : 'false';
271277
process.env.TLS = tls;

0 commit comments

Comments
 (0)