Skip to content
Merged
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
11 changes: 10 additions & 1 deletion scripts/setup-origin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,16 @@ fi

# ------------------------------------------------------------------ nginx

step "writing the nginx server block"
# A name can bring its own server block: /etc/moshpit/templates/<name>.conf
# (MOSHPIT_TEMPLATE_DIR). Without it, a name whose site is a proxy to an app
# (seo.rank, live.streaming) was rewritten back to the static webroot by the
# next renewal, which re-runs this script. MOSHPIT_TEMPLATE, when set, still
# wins, for a box whose every name is served the same way.
NAME_TEMPLATE="${MOSHPIT_TEMPLATE_DIR:-/etc/moshpit/templates}/$NAME.conf"
if [ -z "${MOSHPIT_TEMPLATE:-}" ] && [ -f "$NAME_TEMPLATE" ]; then
TEMPLATE="$NAME_TEMPLATE"
fi
step "writing the nginx server block from $TEMPLATE"
CONF="$SITEDIR/$NAME"
if [ "$DRY_RUN" = "0" ]; then
mkdir -p "$SITEDIR" "$ENABLEDIR" "$WEBROOT"
Expand Down
14 changes: 14 additions & 0 deletions tests/setup-origin-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,17 @@ describe("moshpit-renew.sh", () => {
assert.match(r.stdout, /1 renewed, 0 failed/);
});
});

describe("setup-origin.sh — a name's own server block", () => {
test("a template named for the site is used, so a renewal keeps its proxy", async () => {
const dir = await tempDir();
const templates = join(dir, "templates");
await mkdir(templates, { recursive: true });
await writeFile(join(templates, "live.streaming.conf"), "server { server_name NAME; }\n");
const own = await sh(setup, ["live.streaming", "--dry-run"], { MOSHPIT_TEMPLATE_DIR: templates, MOSHPIT_TEMPLATE: "" });
assert.equal(own.code, 0, own.stderr);
assert.match(own.stderr + own.stdout, new RegExp(`server block from ${join(templates, "live.streaming.conf").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
const other = await sh(setup, ["blue.eggs", "--dry-run"], { MOSHPIT_TEMPLATE_DIR: templates, MOSHPIT_TEMPLATE: "" });
assert.match(other.stderr + other.stdout, /server block from .*moshpit-origin\.conf/);
});
});
Loading