Repository navigation
Phase 1: data.nemar.org route + manifest + HTML index - #502
Merged
neuromechanist merged 2 commits intoMay 15, 2026
Merged
neuromechanist merged 2 commits into
neuromechanist merged 2 commits into
Conversation
Phase 1 of epic #449. Public, anonymous, BIDS-shaped HTTPS access to every published dataset via a Cloudflare Workers route at data.nemar.org and a path-based mount at api.nemar.org/data/* (so the workers.dev dev fallback serves the same handlers). - backend/src/services/data-router.ts: pure functions resolveVersion, resolveFile, buildRedirectUrl, renderIndexHtml. Annex keys -> presigned S3 GET; git: keys -> raw.githubusercontent URL pinned to the version tag. - backend/src/routes/data.ts: Hono sub-app. Public datasets only; private/unpublished return 404 (no existence leak). manifest.json endpoint emits the existing VersionManifest as a flat array with presigned URLs and checksums. - backend/src/index.ts: hostname middleware forks to dataRoutes when the Host header is data.nemar.org; path-based mount at /data wires the same handlers on every other hostname. - backend/wrangler-sccn.toml: data.nemar.org added as a Workers custom domain alongside api.nemar.org. Dev environment keeps the workers.dev fallback and uses the path-based mount. - 21 unit tests on pure functions; E2E suite skips gracefully when nm099999 is not currently published. - docs/guides/downloading.md + docs/reference/data-api.md. Closes #495.
Critical:
- Hostname fork for data.nemar.org now rewrites the URL to /data/<path>
and re-enters api.fetch, so requests inherit the full middleware stack
(logger, secureHeaders, cors, rateLimiter, maintenanceMode, onError).
Previously dataRoutes.fetch was called directly, bypassing everything.
- Read the hostname from c.req.url instead of the Host header so a forged
Host: cannot steer api.nemar.org traffic into the data branch.
- loadManifest now try/catches JSON.parse and validates manifest.files is
a non-null object before downstream code iterates it.
- /:datasetId, /:datasetId/, and /:datasetId/:version handlers all gate
on loadPublishedDataset before producing any response body. The
/:datasetId placeholder additionally escapes the id and URL-encodes the
href so a request like /<script> can never reflect into the HTML.
Important:
- loadPublishedDataset emits one structured console.log per reject branch
(invalid id / not in catalog / non-public visibility) so operators can
tell scraping from honest 404s in wrangler tail.
- getManifest in s3.ts now logs S3 403 separately from 404 so a
credentials regression doesn't silently 404 every published dataset.
- manifest.json builder catches per-entry buildRedirectUrl failures and
emits {url: null, error} for the bad rows instead of failing the whole
response; healthy rows still resolve normally.
- Added exhaustive 'never' guard in fileOrIndexHandler so future
ResolvedFile arms fail at build time.
- Exported PresignedUrlOptions from s3.ts and reused it in data-router,
dropping the duplicate S3Options interface.
- Pinned the /manifest.json response shape to a named PublicManifestEntry
type (now exported, externally consumable).
- DirectoryEntry is now a discriminated union ({kind:'file'|'dir'})
instead of {isDir: boolean, size?: number}.
- humanSize guards NaN / Infinity / negative inputs.
- resolveFile returns an empty directory listing for the root of an
empty manifest rather than 404, so the renderer can show valid UX.
Tests:
- Added unit coverage for MD5E and SHA1E annex backends, unicode +
special-char filenames, URL-encoded path traversal, empty manifest,
prototype-pollution-shaped segments, humanSize edge cases.
- E2E now skips itself when TEST_API_URL points at *.nemar.org unless
TEST_ALLOW_PROD=1 is also set, asserts the structured error body, and
adds dataset-root response coverage. 30 unit tests pass.
Follow-up:
- #503 tracks the git:-redirect 404 risk (Phase 3).
Contributor
Author
Review-round 1 applied (commit fe662aa)Addressed all Critical and Important findings from the four-agent review. Summary: Critical fixes
Important
Tests
Deferred (with reasoning)
Ready for re-review. |
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR502Version: 🤖 Updated on each push. |
neuromechanist
merged commit May 15, 2026
9aa728c
into
feature/issue-449-epic-data-https
1 check passed
This was referenced May 15, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of epic #449. Public, anonymous, BIDS-shaped HTTPS access to every published dataset over Cloudflare Workers at `data.nemar.org`. The same handlers are also reachable under `/data/...` on every hostname (api.nemar.org, workers.dev dev fallback) so dev testing doesn't need a separate custom domain.
Closes #495.
Part of epic #449.
Files
Test plan
Out of scope (later phases)
Manual prereq before prod deploy
The `data.nemar.org` zone must be added to the SCCN Cloudflare account; `custom_domain = true` then auto-manages DNS + TLS. One-time dashboard step.