From 38d6a5b30e289d3ebe9771c772870e9f60135c4d Mon Sep 17 00:00:00 2001 From: megumii Date: Mon, 18 Sep 2023 22:52:01 +0700 Subject: [PATCH 01/16] fix(docker): correct healthcheck endpoint in Dockerfile Fixes the Dockerfile referring to an old healthcheck endpoint. The new one is under `/ar-io` to avoid potential conflicts with Arweave node paths. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 27477076..90edf500 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ VOLUME /app/data # EXPOSE PORT AND SETUP HEALTHCHECK EXPOSE 4000 -HEALTHCHECK CMD curl --fail http://localhost:4000/healthcheck || exit 1 +HEALTHCHECK CMD curl --fail http://localhost:4000/ar-io/healthcheck || exit 1 # ADD LABELS LABEL org.opencontainers.image.title="ar.io Core Service" From f5d602170bfd2596fb4f38aec0deb70189d01116 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Mon, 18 Sep 2023 16:39:58 -0500 Subject: [PATCH 02/16] fix(envoy): remove old healthcheck route All ar.io specific routes are now under `/ar-io` on the gateway. --- envoy/envoy.template.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/envoy/envoy.template.yaml b/envoy/envoy.template.yaml index c95fb9a6..66c05da6 100644 --- a/envoy/envoy.template.yaml +++ b/envoy/envoy.template.yaml @@ -40,13 +40,6 @@ static_resources: retry_on: '5xx,reset,retriable-status-codes' retriable_status_codes: 404 num_retries: 5 - - match: { prefix: '/healthcheck' } - route: - cluster: ario_gateways - retry_policy: - retry_on: '5xx,reset,retriable-status-codes' - retriable_status_codes: 404 - num_retries: 5 - match: { prefix: '/graphql' } route: cluster: graphql_gateways From 44b7d87bbeda1ce04a86e972a5c7bd3897002256 Mon Sep 17 00:00:00 2001 From: rixcian Date: Thu, 14 Sep 2023 10:18:52 +0200 Subject: [PATCH 03/16] docs: add .env.example --- .env.example | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..8c506ced --- /dev/null +++ b/.env.example @@ -0,0 +1,50 @@ +# Blockchain height to start from (0 = genesis block) +# START_HEIGHT=0 + +# Blockchain height to stop at (Infinity = keep syncing until stopped) +# STOP_HEIGHT="Infinity" + +# Arweave node to use for fetching data +# TRUSTED_NODE_URL="https://arweave.net" + +# Arweave node to use for proxying requests +# TRUSTED_GATEWAY_URL="https://arweave.net" + +# ArNS gateway +# TRUSTED_ARNS_GATEWAY_URL="https://__NAME__.arweave.dev" + +# If true, use indexed data as a cache and skip fetching data from the node +# SKIP_CACHE=false + +# AR.IO node exposed port number +# PORT=4000 + +# Number from 0 to Infinity, representing the probability of a request failing +# SIMULATED_REQUEST_FAILURE_RATE=0 + +# Arweave wallet address used for staking and rewards +# AR_IO_WALLET="" + +# Admin key used for accessing the admin API +# ADMIN_API_KEY="secret" + +# If true, ar.io node will start indexing missing bundles +# BACKFILL_BUNDLE_RECORDS="false" + +# If true, all indexed bundles will be reprocessed with the new filters (you can use this when you change the filters) +# FILTER_CHANGE_REPROCESS="false" + +# Only bundles compliant with this filter will be unbundled +# ANS104_UNBUNDLE_FILTER='{"never": true}' + +# Only bundles compliant with this filter will be indexed +# ANS104_INDEX_FILTER='{"never": true}' + +# Root host for ArNS +# ARNS_ROOT_HOST="" + +# Protocol setting in process of creating sandbox domain in ArNS (ARNS_ROOT_HOST needs to be set for this env to have any effect) +# SANDBOX_PROTOCOL="" + +# If true, start indexing blocks, tx, ANS104 bundles +# START_WRITERS="true" From ad4b9c20a9ac8d7da2cbcbc7e02c97b376e2d49c Mon Sep 17 00:00:00 2001 From: rixcian Date: Thu, 14 Sep 2023 10:19:50 +0200 Subject: [PATCH 04/16] chore: add jetbrains ide cache files to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6e897ae4..4255f5a2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,8 @@ test-results.json /.vscode .DS_Store +# JetBrains +/.idea + # Exceptions !/data/.gitkeep From 4f008b20919f67dedf56d6eb4b0d48988d130af8 Mon Sep 17 00:00:00 2001 From: rixcian Date: Fri, 15 Sep 2023 16:28:23 +0200 Subject: [PATCH 05/16] docs: describe envs in a clear table --- docs/envs.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/envs.md diff --git a/docs/envs.md b/docs/envs.md new file mode 100644 index 00000000..907c3f3b --- /dev/null +++ b/docs/envs.md @@ -0,0 +1,22 @@ +# ENVs +This document describes the environment variables that can be used to configure the `ar.io` node. + +| ENV_NAME | TYPE | DEFAULT_VALUE | DESCRIPTION | +|--------------------------------|----------------------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------| +| START_HEIGHT | Number or "Infinity" | 0 | Starting block height for node synchronization (0 = start from the beginning) | +| STOP_HEIGHT | Number or "Infinity" | "Infinity" | Stop block height for node synchronization (Infinity = keep syncing until stopped) | +| TRUSTED_NODE_URL | String | "https://arweave.net" | Arweave node to use for fetching data | +| TRUSTED_GATEWAY_URL | String | "https://arweave.net" | Arweave node to use for proxying requests | +| TRUSTED_ARNS_GATEWAY_URL | String | "https://__NAME__.arweave.dev" | ArNS gateway | +| SKIP_CACHE | Boolean | false | If true, use indexed data as a cache and skip fetching data from the node | +| PORT | Number | 4000 | AR.IO node exposed port number | +| SIMULATED_REQUEST_FAILURE_RATE | Number | 0 | Number from 0 to Infinity, representing the probability of a request failing | +| AR_IO_WALLET | String | "" | Arweave wallet address used for staking and rewards | +| ADMIN_API_KEY | String | Generated | API key used for admin API requests (if not set, it's generated and logged into the console) | +| BACKFILL_BUNDLE_RECORDS | Boolean | false | If true, ar.io node will start indexing missing bundles | +| FILTER_CHANGE_REPROCESS | Boolean | false | If true, all indexed bundles will be reprocessed with the new filters (you can use this when you change the filters) | +| ANS104_UNBUNDLE_FILTER | String | '{"never": true}' | Only bundles compliant with this filter will be unbundled | +| ANS104_INDEX_FILTER | String | '{"never": true}' | Only bundles compliant with this filter will be indexed | +| ARNS_ROOT_HOST | String | undefined | Domain name for ArNS host | +| SANDBOX_PROTOCOL | String | undefined | Protocol setting in process of creating sandbox domain in ArNS (ARNS_ROOT_HOST needs to be set for this env to have any effect) | +| START_WRITERS | Boolean | true | If true, start indexing blocks, tx, ANS104 bundles | From f48b6635ab7d8e23569b95dc5e76480e31430419 Mon Sep 17 00:00:00 2001 From: rixcian Date: Fri, 15 Sep 2023 16:28:42 +0200 Subject: [PATCH 06/16] docs: update description of some envs --- .env.example | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 8c506ced..42a1bd6d 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ -# Blockchain height to start from (0 = genesis block) +# Starting block height for node synchronization (0 = start from the beginning) # START_HEIGHT=0 -# Blockchain height to stop at (Infinity = keep syncing until stopped) +# Stop block height for node synchronization (Infinity = keep syncing until stopped) # STOP_HEIGHT="Infinity" # Arweave node to use for fetching data @@ -29,10 +29,10 @@ # ADMIN_API_KEY="secret" # If true, ar.io node will start indexing missing bundles -# BACKFILL_BUNDLE_RECORDS="false" +# BACKFILL_BUNDLE_RECORDS=false # If true, all indexed bundles will be reprocessed with the new filters (you can use this when you change the filters) -# FILTER_CHANGE_REPROCESS="false" +# FILTER_CHANGE_REPROCESS=false # Only bundles compliant with this filter will be unbundled # ANS104_UNBUNDLE_FILTER='{"never": true}' @@ -47,4 +47,4 @@ # SANDBOX_PROTOCOL="" # If true, start indexing blocks, tx, ANS104 bundles -# START_WRITERS="true" +# START_WRITERS=true From a6add2f6b520e6aa8d04f205f9b4c2b11617f859 Mon Sep 17 00:00:00 2001 From: rixcian Date: Sat, 23 Sep 2023 09:16:44 +0200 Subject: [PATCH 07/16] docs: add missing envs --- .env.example | 6 ++++++ docs/envs.md | 2 ++ 2 files changed, 8 insertions(+) diff --git a/.env.example b/.env.example index 42a1bd6d..2704c0c5 100644 --- a/.env.example +++ b/.env.example @@ -16,6 +16,12 @@ # If true, use indexed data as a cache and skip fetching data from the node # SKIP_CACHE=false +# Adds an "INSTANCE_ID" field to output logs +# INSTANCE_ID="" + +# Sets the format of output logs, accepts "simple" and "json" +# LOG_FORMAT="simple" + # AR.IO node exposed port number # PORT=4000 diff --git a/docs/envs.md b/docs/envs.md index 907c3f3b..d1e0d320 100644 --- a/docs/envs.md +++ b/docs/envs.md @@ -8,6 +8,8 @@ This document describes the environment variables that can be used to configure | TRUSTED_NODE_URL | String | "https://arweave.net" | Arweave node to use for fetching data | | TRUSTED_GATEWAY_URL | String | "https://arweave.net" | Arweave node to use for proxying requests | | TRUSTED_ARNS_GATEWAY_URL | String | "https://__NAME__.arweave.dev" | ArNS gateway | +| INSTANCE_ID | String | "" | Adds an "INSTACE_ID" field to output logs | +| LOG_FORMAT | String | "simple" | Sets the format of output logs, accepts "simple" and "json" | | SKIP_CACHE | Boolean | false | If true, use indexed data as a cache and skip fetching data from the node | | PORT | Number | 4000 | AR.IO node exposed port number | | SIMULATED_REQUEST_FAILURE_RATE | Number | 0 | Number from 0 to Infinity, representing the probability of a request failing | From 79e9ed12b7c5d559ae5a0e4644478b73937c4cda Mon Sep 17 00:00:00 2001 From: rixcian Date: Sat, 23 Sep 2023 09:19:55 +0200 Subject: [PATCH 08/16] docs: remove single quotes from envs --- .env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 2704c0c5..4fbcf2d2 100644 --- a/.env.example +++ b/.env.example @@ -41,10 +41,10 @@ # FILTER_CHANGE_REPROCESS=false # Only bundles compliant with this filter will be unbundled -# ANS104_UNBUNDLE_FILTER='{"never": true}' +# ANS104_UNBUNDLE_FILTER={"never": true} # Only bundles compliant with this filter will be indexed -# ANS104_INDEX_FILTER='{"never": true}' +# ANS104_INDEX_FILTER={"never": true} # Root host for ArNS # ARNS_ROOT_HOST="" From eb843a76cf7389fefac5df908021edc1a1a754b7 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Mon, 25 Sep 2023 09:27:13 -0500 Subject: [PATCH 09/16] docs: correct description of SIMULATED_REQUEST_FAILURE_RATE The range is from 0 to 1 rather than 0 to Infinity. If set to 1, all requests will fail. --- .env.example | 2 +- docs/envs.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 4fbcf2d2..296665af 100644 --- a/.env.example +++ b/.env.example @@ -25,7 +25,7 @@ # AR.IO node exposed port number # PORT=4000 -# Number from 0 to Infinity, representing the probability of a request failing +# Number from 0 to 1, representing the probability of a request failing # SIMULATED_REQUEST_FAILURE_RATE=0 # Arweave wallet address used for staking and rewards diff --git a/docs/envs.md b/docs/envs.md index d1e0d320..303d7e8d 100644 --- a/docs/envs.md +++ b/docs/envs.md @@ -12,7 +12,7 @@ This document describes the environment variables that can be used to configure | LOG_FORMAT | String | "simple" | Sets the format of output logs, accepts "simple" and "json" | | SKIP_CACHE | Boolean | false | If true, use indexed data as a cache and skip fetching data from the node | | PORT | Number | 4000 | AR.IO node exposed port number | -| SIMULATED_REQUEST_FAILURE_RATE | Number | 0 | Number from 0 to Infinity, representing the probability of a request failing | +| SIMULATED_REQUEST_FAILURE_RATE | Number | 0 | Number from 0 to 1, representing the probability of a request failing | | AR_IO_WALLET | String | "" | Arweave wallet address used for staking and rewards | | ADMIN_API_KEY | String | Generated | API key used for admin API requests (if not set, it's generated and logged into the console) | | BACKFILL_BUNDLE_RECORDS | Boolean | false | If true, ar.io node will start indexing missing bundles | From 38210b9979d50ceb00a24feb12bd244b09f1d3c4 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Mon, 25 Sep 2023 09:39:55 -0500 Subject: [PATCH 10/16] docs: correct description of SKIP_CACHE Setting SKIP_CACHE to 'true' instructs the node to skip the local cache and always fetch headers from the Arweave node. --- .env.example | 2 +- docs/envs.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 296665af..03be57c8 100644 --- a/.env.example +++ b/.env.example @@ -13,7 +13,7 @@ # ArNS gateway # TRUSTED_ARNS_GATEWAY_URL="https://__NAME__.arweave.dev" -# If true, use indexed data as a cache and skip fetching data from the node +# If true, skips the local cache and always fetches headers from the node # SKIP_CACHE=false # Adds an "INSTANCE_ID" field to output logs diff --git a/docs/envs.md b/docs/envs.md index 303d7e8d..97dd8dc1 100644 --- a/docs/envs.md +++ b/docs/envs.md @@ -10,7 +10,7 @@ This document describes the environment variables that can be used to configure | TRUSTED_ARNS_GATEWAY_URL | String | "https://__NAME__.arweave.dev" | ArNS gateway | | INSTANCE_ID | String | "" | Adds an "INSTACE_ID" field to output logs | | LOG_FORMAT | String | "simple" | Sets the format of output logs, accepts "simple" and "json" | -| SKIP_CACHE | Boolean | false | If true, use indexed data as a cache and skip fetching data from the node | +| SKIP_CACHE | Boolean | false | If true, skips the local cache and always fetches headers from the node | | PORT | Number | 4000 | AR.IO node exposed port number | | SIMULATED_REQUEST_FAILURE_RATE | Number | 0 | Number from 0 to 1, representing the probability of a request failing | | AR_IO_WALLET | String | "" | Arweave wallet address used for staking and rewards | From e71bda890a27ba9c73711e532ac8c26629438e6d Mon Sep 17 00:00:00 2001 From: K Date: Wed, 20 Sep 2023 17:02:38 +0000 Subject: [PATCH 11/16] feat(sandbox): add subdomain support Enables the sandbox feature to work when the node is hosted on a subdomain. Added to allow hosting on exiting domains. --- src/middleware/sandbox.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/middleware/sandbox.ts b/src/middleware/sandbox.ts index aa82c631..ab6604e9 100644 --- a/src/middleware/sandbox.ts +++ b/src/middleware/sandbox.ts @@ -21,9 +21,10 @@ import { base32 } from 'rfc4648'; import { fromB64Url } from '../lib/encoding.js'; -function getRequestSandbox(req: Request): string | undefined { - if (req.subdomains.length === 1) { - return req.subdomains[0]; +function getRequestSandbox(req: Request, rootHost: string): string | undefined { + const rootHostSubdomainLength = rootHost.split('.').length - 2; + if (req.subdomains.length > rootHostSubdomainLength) { + return req.subdomains[req.subdomains.length - 1]; } return undefined; } @@ -55,7 +56,7 @@ export function createSandboxMiddleware({ return; } - const reqSandbox = getRequestSandbox(req); + const reqSandbox = getRequestSandbox(req, rootHost); const idSandbox = sandboxFromId(id); if (reqSandbox !== idSandbox) { const queryString = url.parse(req.originalUrl).query ?? ''; From 5057c6dd1a0988e1908db2ddd61bb970e81e970a Mon Sep 17 00:00:00 2001 From: K Date: Wed, 20 Sep 2023 17:03:10 +0000 Subject: [PATCH 12/16] feat(arns): add subdomain support Enables the arns feature to work when the node is hosted on a subdomain. Added to allow hosting on exiting domains. --- src/app.ts | 1 + src/middleware/arns.ts | 41 +++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/app.ts b/src/app.ts index 8514859c..32589ac7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -83,6 +83,7 @@ if (config.ARNS_ROOT_HOST !== undefined) { app.use( createArnsMiddleware({ dataHandler, + rootHost: config.ARNS_ROOT_HOST, nameResolver: system.nameResolver, }), ); diff --git a/src/middleware/arns.ts b/src/middleware/arns.ts index bfa28e4e..2483f61b 100644 --- a/src/middleware/arns.ts +++ b/src/middleware/arns.ts @@ -25,33 +25,42 @@ const EXCLUDED_SUBDOMAINS = new Set('www'); export const createArnsMiddleware = ({ dataHandler, + rootHost, nameResolver, }: { dataHandler: Handler; + rootHost: string; nameResolver: NameResolver; }): Handler => asyncMiddleware(async (req, res, next) => { + const rootHostSubdomainLength = rootHost.split('.').length - 2; if ( - Array.isArray(req.subdomains) && - req.subdomains.length === 1 && - !EXCLUDED_SUBDOMAINS.has(req.subdomains[0]) && + // Ignore subdomains that are part of the ArNS root hostname. + !Array.isArray(req.subdomains) || + req.subdomains.length === rootHostSubdomainLength + ) { + next(); + return; + } + const arnsSubdomain = req.subdomains[req.subdomains.length - 1]; + if ( + EXCLUDED_SUBDOMAINS.has(arnsSubdomain) || // Avoid collisions with sandbox URLs by ensuring the subdomain length // is below the mininimum length of a sandbox subdomain. Undernames are // are an exception because they can be longer and '_' cannot appear in // base32. - (req.subdomains[0].length <= 48 || req.subdomains[0].match(/_/)) + (arnsSubdomain.length > 48 && !arnsSubdomain.match(/_/)) ) { - const { resolvedId, ttl } = await nameResolver.resolve(req.subdomains[0]); - if (resolvedId !== undefined) { - res.header('X-ArNS-Resolved-Id', resolvedId); - res.header('X-ArNS-TTL-Seconds', ttl.toString()); - res.header('Cache-Control', `public, max-age=${ttl}`); - dataHandler(req, res, next); - return; - } else { - sendNotFound(res); - return; - } + next(); + return; + } + const { resolvedId, ttl } = await nameResolver.resolve(arnsSubdomain); + if (resolvedId === undefined) { + sendNotFound(res); + return; } - next(); + res.header('X-ArNS-Resolved-Id', resolvedId); + res.header('X-ArNS-TTL-Seconds', ttl.toString()); + res.header('Cache-Control', `public, max-age=${ttl}`); + dataHandler(req, res, next); }); From 1cfa5da077330ad7a7a809f17161126188de9e36 Mon Sep 17 00:00:00 2001 From: K Date: Tue, 26 Sep 2023 08:35:38 +0000 Subject: [PATCH 13/16] refactor(sandbox, arns): switch params to config As both middlewares need the root host's subdomain count, moving it to the config eliminates duplicates. This also allows to remove the rootHost constructor param and take it directly from the config. --- src/app.ts | 2 -- src/config.ts | 2 ++ src/middleware/arns.ts | 8 +++----- src/middleware/sandbox.ts | 14 ++++++-------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/app.ts b/src/app.ts index 32589ac7..6df5b94a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -83,14 +83,12 @@ if (config.ARNS_ROOT_HOST !== undefined) { app.use( createArnsMiddleware({ dataHandler, - rootHost: config.ARNS_ROOT_HOST, nameResolver: system.nameResolver, }), ); app.use( createSandboxMiddleware({ - rootHost: config.ARNS_ROOT_HOST, sandboxProtocol: config.SANDBOX_PROTOCOL, }), ); diff --git a/src/config.ts b/src/config.ts index 6c3fed52..bf27aab2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -70,6 +70,8 @@ export const ANS104_INDEX_FILTER = createFilter( JSON.parse(ANS104_INDEX_FILTER_STRING), ); export const ARNS_ROOT_HOST = env.varOrUndefined('ARNS_ROOT_HOST'); +export const ROOT_HOST_SUBDOMAIN_LENGTH = + ARNS_ROOT_HOST !== undefined ? ARNS_ROOT_HOST.split('.').length - 2 : 0; export const SANDBOX_PROTOCOL = env.varOrUndefined('SANDBOX_PROTOCOL'); export const START_WRITERS = env.varOrDefault('START_WRITERS', 'true') === 'true'; diff --git a/src/middleware/arns.ts b/src/middleware/arns.ts index 2483f61b..d537bba9 100644 --- a/src/middleware/arns.ts +++ b/src/middleware/arns.ts @@ -18,6 +18,7 @@ import { Handler } from 'express'; import { asyncMiddleware } from 'middleware-async'; +import * as config from '../config.js'; import { sendNotFound } from '../routes/data.js'; import { NameResolver } from '../types.js'; @@ -25,24 +26,21 @@ const EXCLUDED_SUBDOMAINS = new Set('www'); export const createArnsMiddleware = ({ dataHandler, - rootHost, nameResolver, }: { dataHandler: Handler; - rootHost: string; nameResolver: NameResolver; }): Handler => asyncMiddleware(async (req, res, next) => { - const rootHostSubdomainLength = rootHost.split('.').length - 2; if ( // Ignore subdomains that are part of the ArNS root hostname. !Array.isArray(req.subdomains) || - req.subdomains.length === rootHostSubdomainLength + req.subdomains.length === config.ROOT_HOST_SUBDOMAIN_LENGTH ) { next(); return; } - const arnsSubdomain = req.subdomains[req.subdomains.length - 1]; + const arnsSubdomain = req.subdomains[config.ROOT_HOST_SUBDOMAIN_LENGTH - 1]; if ( EXCLUDED_SUBDOMAINS.has(arnsSubdomain) || // Avoid collisions with sandbox URLs by ensuring the subdomain length diff --git a/src/middleware/sandbox.ts b/src/middleware/sandbox.ts index ab6604e9..41f0cc53 100644 --- a/src/middleware/sandbox.ts +++ b/src/middleware/sandbox.ts @@ -19,11 +19,11 @@ import { Handler, Request } from 'express'; import url from 'node:url'; import { base32 } from 'rfc4648'; +import * as config from '../config.js'; import { fromB64Url } from '../lib/encoding.js'; -function getRequestSandbox(req: Request, rootHost: string): string | undefined { - const rootHostSubdomainLength = rootHost.split('.').length - 2; - if (req.subdomains.length > rootHostSubdomainLength) { +function getRequestSandbox(req: Request): string | undefined { + if (req.subdomains.length > config.ROOT_HOST_SUBDOMAIN_LENGTH) { return req.subdomains[req.subdomains.length - 1]; } return undefined; @@ -38,14 +38,12 @@ function sandboxFromId(id: string): string { } export function createSandboxMiddleware({ - rootHost, sandboxProtocol, }: { - rootHost?: string; sandboxProtocol?: string; }): Handler { return (req, res, next) => { - if (rootHost === undefined) { + if (config.ARNS_ROOT_HOST === undefined) { next(); return; } @@ -56,7 +54,7 @@ export function createSandboxMiddleware({ return; } - const reqSandbox = getRequestSandbox(req, rootHost); + const reqSandbox = getRequestSandbox(req); const idSandbox = sandboxFromId(id); if (reqSandbox !== idSandbox) { const queryString = url.parse(req.originalUrl).query ?? ''; @@ -64,7 +62,7 @@ export function createSandboxMiddleware({ const protocol = sandboxProtocol ?? (req.secure ? 'https' : 'http'); return res.redirect( 302, - `${protocol}://${idSandbox}.${rootHost}${path}?${queryString}`, + `${protocol}://${idSandbox}.${config.ARNS_ROOT_HOST}${path}?${queryString}`, ); } From 38b27aa8eef2774cad119f69be56eb4593805f33 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Tue, 26 Sep 2023 17:29:09 -0500 Subject: [PATCH 14/16] fix: correct array indexing in ArNS middleware --- src/middleware/arns.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middleware/arns.ts b/src/middleware/arns.ts index d537bba9..e51d4476 100644 --- a/src/middleware/arns.ts +++ b/src/middleware/arns.ts @@ -40,7 +40,7 @@ export const createArnsMiddleware = ({ next(); return; } - const arnsSubdomain = req.subdomains[config.ROOT_HOST_SUBDOMAIN_LENGTH - 1]; + const arnsSubdomain = req.subdomains[req.subdomains.length - 1]; if ( EXCLUDED_SUBDOMAINS.has(arnsSubdomain) || // Avoid collisions with sandbox URLs by ensuring the subdomain length From d5a0512626aa505d76b07767e18cde1fc27f1f60 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Fri, 29 Sep 2023 15:49:39 -0500 Subject: [PATCH 15/16] chore: add testing guidance to CONTRIBUTING.md --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89307fcd..e193138e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,8 @@ NOTE: Contribution implies licensing under the terms of [LICENSE] - Ensure commit messages adequately explain the reasons for the changes. - Ensure changes are consistent with the [principles and practices] outlined in the README. +- Ensure that tests were added or that the manual testing process followed is + described in the PR. - Run [lint]. - Run the [unit tests]. From f1d23811eab0bb2502ee9944664e5fff483ecfc0 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Fri, 29 Sep 2023 16:22:15 -0500 Subject: [PATCH 16/16] chore: small working improvement in CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e193138e..24c732d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ NOTE: Contribution implies licensing under the terms of [LICENSE] - Keep the first line short but informative. - Provide explanation of why the change is being made in the commit message body. -- Prefer copying relevant information into the commit body over linking to them. +- Prefer copying relevant information into the commit body over linking to it. - Consider whether your commit message includes enough detail for someone to be able to understand it in the future.