@rcpooley/concord-kit 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -152,7 +152,8 @@ wildcards, on an app for names it owns) and every route must be covered by
152
152
  exactly one, most specific first.
153
153
 
154
154
  Apps can contribute shared edge material by name: `features` (snippet pairs a
155
- route opts into), `secretFiles`, `logFormats` and `rateLimits`.
155
+ route opts into, plus an optional `http` part included once in nginx.conf for
156
+ the `map`s they read), `secretFiles`, `logFormats` and `rateLimits`.
156
157
 
157
158
  Also exported: `nginxEdge()` itself, `certFor`, `covers`, `EDGE_CONF`,
158
159
  `PROXY_CONF`, and the per-machine pieces (`dockerAptRepo`, `DOCKER_PACKAGES`,
package/dist/assemble.js CHANGED
@@ -304,9 +304,15 @@ function validate(all, fleet) {
304
304
  seenEdge.set(key, a.name);
305
305
  }
306
306
  }
307
- for (const [host, m] of Object.entries(fleet)) {
308
- if (m.sleeps && m.edge) {
309
- throw new Error(`hosts: ${host} sleeps and declares an edge — an ingress cannot sleep`);
307
+ // A sleeping machine may run an edge, but only for its own apps. When it is
308
+ // asleep its routes are down along with the apps behind them, which is no
309
+ // worse than the apps being down. Fronting ANOTHER machine's app would make
310
+ // that app's reachability depend on a lid, so that stays an error.
311
+ for (const a of all) {
312
+ const edgeHost = a.servedBy ?? a.host;
313
+ if (edgeHost !== a.host && fleet[edgeHost]?.sleeps) {
314
+ throw new Error(`apps: "${a.name}" runs on ${a.host} but is served by ${edgeHost}, which sleeps — ` +
315
+ `a sleeping machine's edge may serve only its own apps`);
310
316
  }
311
317
  }
312
318
  }
@@ -177,10 +177,17 @@ export type RateLimitGroup = {
177
177
  * discards every one from the enclosing `server`, so a feature that touches
178
178
  * headers CANNOT be expressed as a single server-scope snippet. Hence two
179
179
  * halves, always in the same two positions. The content is entirely data.
180
+ *
181
+ * A third, optional part holds what is only legal at http scope — a `map`
182
+ * the halves read, typically. It is included once in nginx.conf whether or not
183
+ * any block opts in, which costs nothing: a map is evaluated only when a
184
+ * variable it defines is used.
180
185
  */
181
186
  export type Feature = {
182
187
  name: string;
183
188
  note?: string;
189
+ /** -> snippets/<name>-http.conf, included once at http scope in nginx.conf. */
190
+ http?: string;
184
191
  /** -> snippets/<name>-server.conf, included before `location /`. */
185
192
  server?: string;
186
193
  /** -> snippets/<name>-location.conf, included immediately after proxy.conf. */
@@ -229,6 +229,12 @@ function renderNginxConf(opts) {
229
229
  note(f.note);
230
230
  out.push(` include /etc/nginx/secrets/${f.name}.conf;`);
231
231
  }
232
+ // 4. The http-scope part of each feature that has one (its `map`s).
233
+ for (const f of opts.features.filter((x) => x.http)) {
234
+ out.push('');
235
+ note(f.note);
236
+ out.push(` include ${EDGE_CONF}/snippets/${f.name}-http.conf;`);
237
+ }
232
238
  // The head ends with a blank line and the tail begins at `sendfile`, so the
233
239
  // injected span owns its own separators: leading blank trimmed, one trailing
234
240
  // blank line to part it from the tail.
@@ -422,6 +428,9 @@ export function nginxEdge(opts) {
422
428
  };
423
429
  });
424
430
  const featureFiles = features.flatMap((f) => [
431
+ ...(f.http
432
+ ? [{ path: `${CONF_DIR}/snippets/${f.name}-http.conf`, mode: '0644', content: f.http }]
433
+ : []),
425
434
  ...(f.server
426
435
  ? [{ path: `${CONF_DIR}/snippets/${f.name}-server.conf`, mode: '0644', content: f.server }]
427
436
  : []),
@@ -530,7 +539,7 @@ export function nginxEdge(opts) {
530
539
  {
531
540
  path: `${CONF_DIR}/nginx.conf`,
532
541
  mode: '0644',
533
- content: renderNginxConf({ logFormats, rateLimits, secretFiles }),
542
+ content: renderNginxConf({ logFormats, rateLimits, secretFiles, features }),
534
543
  },
535
544
  ...confFiles,
536
545
  { path: `${CONF_DIR}/snippets/proxy.conf`, mode: '0644', content: PROXY_CONF },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rcpooley/concord-kit",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Opinionated building blocks for a Concord config repo: apps as one file each, machines that derive their base layers, an nginx edge with derived certificate coverage, and assemble() to put the modules in order.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/rcpooley/concord/tree/main/kit",