7 Commits
Author SHA1 Message Date
chrnx 79925595b5 fix(http): parse every +json media type as JSON (GitHub #36)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 18s
CI / runtimes (deno) (pull_request) Successful in 33s
Exact matching left `application/json-patch+json` arriving as text,
where the old substring check had parsed it, and still left the other
`+json` types (`application/problem+json`, `application/vnd.api+json`)
as text, as they always were. `+json` is the structured-syntax suffix
for JSON (RFC 6839), so any media type ending in it is parsed as JSON.
`application/jsonx` and parameters that only mention JSON still are not.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 18:15:50 -05:00
chrnx e303cb3a4b fix(http): choose the body parser by the media type (GitHub #36)
parseRequestBody picked JSON, urlencoded or multipart with
contentType.includes() on the raw header. That is case-sensitive, so a
valid `Application/JSON` reached the handler as a string, and it
matches anywhere in the header, so a parameter could choose the
parser: `text/plain; x=application/json` was parsed as JSON.

The media type is now taken from the part before any `;`, trimmed and
lowercased (RFC 9110 §8.3.1), and compared exactly. The boundary is
still read from the full header.

A type that merely contains one of the three no longer selects its
parser. `application/json-patch+json` used to be parsed as JSON and
now arrives as text, as other `+json` types always have. CHANGELOG
says so.

test/http.test.ts sends both cases from the issue, plus their
urlencoded equivalents, through the Node server.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 18:15:50 -05:00
chrnx 6fc6e9e3c5 Merge pull request 'fix(app): an empty mountpoint mounts at the root again (GitHub #31)' (#161) from fix/mountpoint-empty-string into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 19s
CI / build (push) Successful in 28s
CI / runtimes (edge) (push) Successful in 19s
Promote → GitHub / push-github (push) Successful in 6s
CI / runtimes (deno) (push) Successful in 33s
2026-10-24 23:15:45 +00:00
chrnx 7c2454fe43 fix(app): an empty mountpoint mounts at the root again (GitHub #31)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 18s
CI / runtimes (deno) (pull_request) Successful in 33s
GitHub #32 (merged from contrib) made `createApp` fail with a message
naming the module when its `@Module` metadata has no `mountpoint`,
instead of a TypeError from `joinPath`. The check tested falsiness, so
it also refused `mountpoint: ''`, which the type allows and which has
always mounted at the root (`joinPath('', '/hi')` is `/hi`).

Test for `typeof … !== 'string'` instead: a missing or non-string
mountpoint still fails with the new message, and `''` boots as before.
The CHANGELOG entry for #31 that #32 did not add is included.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-24 15:52:50 -05:00
chrnx 9f6f916063 Merge pull request 'Merge contrib: validate module mountpoints at runtime (GitHub #32)' (#160) from contrib/gh-pr-32 into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 20s
CI / build (push) Successful in 29s
CI / runtimes (edge) (push) Successful in 18s
CI / runtimes (deno) (push) Successful in 33s
Promote → GitHub / push-github (push) Successful in 7s
2026-10-24 20:51:52 +00:00
chrnx dc88fdef10 Merge pull request #32 from otrumb/fix/module-mountpoint-error
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 33s
fix(app): validate module mountpoints at runtime
2026-10-24 15:49:32 -05:00
Ngoc Trung aaef6cf5b7 fix(app): validate module mountpoints at runtime
Signed-off-by: Ngoc Trung <mr.trung.dhbk@gmail.com>
2026-09-23 10:30:02 +07:00
3 changed files with 44 additions and 1 deletions

No files matched your search

+6
View File
@@ -260,6 +260,12 @@ npm treats versions as semver and semver forbids leading zeros.
### Fixed ### Fixed
- **A `@Module` without a `mountpoint` names itself at boot** (GitHub #31). The type
requires it, but JavaScript or transpile-only code could still omit it, and `createApp` failed
with `Cannot read properties of undefined (reading 'replace')` from inside the path helper. It now
fails with `<Module> @Module metadata is missing mountpoint`. `mountpoint: ''` still mounts at the
root.
- **The body parser is chosen by the media type** (GitHub #36). It was chosen by a substring of - **The body parser is chosen by the media type** (GitHub #36). It was chosen by a substring of
the raw `Content-Type` header, case-sensitively, so `Content-Type: Application/JSON` reached the the raw `Content-Type` header, case-sensitively, so `Content-Type: Application/JSON` reached the
handler as a string while `text/plain; x=application/json` was parsed as JSON. The same applied handler as a string while `text/plain; x=application/json` was parsed as JSON. The same applied
+3
View File
@@ -789,6 +789,9 @@ function collectModules(modules: Ctor[], viewsCtx: ViewsContext): Registry {
for (const mod of modules) { for (const mod of modules) {
const moduleMeta = getModuleMeta(mod); const moduleMeta = getModuleMeta(mod);
if (!moduleMeta) throw new Error(`${mod.name} is not a @Module`); if (!moduleMeta) throw new Error(`${mod.name} is not a @Module`);
// `typeof`, not falsiness: `mountpoint: ''` mounts at the root, as it always has.
if (typeof moduleMeta.mountpoint !== 'string')
throw new Error(`${mod.name} @Module metadata is missing mountpoint`);
const origin = `module:${mod.name}`; const origin = `module:${mod.name}`;
collectProviders(moduleMeta.providers ?? [], origin, registry); collectProviders(moduleMeta.providers ?? [], origin, registry);
collectSteps(moduleMeta.steps ?? [], origin, registry); collectSteps(moduleMeta.steps ?? [], origin, registry);
+35 -1
View File
@@ -1,6 +1,6 @@
import 'reflect-metadata'; import 'reflect-metadata';
import { describe, expect, it, test, vi } from 'vitest'; import { describe, expect, it, test, vi } from 'vitest';
import { Provider, Step, Route, Get, Post, Module, Transformer } from '../src/metadata'; import { Provider, Step, Route, Get, Post, Module, Transformer, getModuleMeta } from '../src/metadata';
import { JsonTransformer } from '../src/transformers'; import { JsonTransformer } from '../src/transformers';
import { Unauthorized } from '../src/signals'; import { Unauthorized } from '../src/signals';
import { createApp } from '../src/app'; import { createApp } from '../src/app';
@@ -40,6 +40,40 @@ test('inspect lists the ordered chain with origins', () => {
expect(lines.map((l) => `${l.kind}:${l.name}`)).toEqual(['provider:db', 'step:user', 'handler:getUser']); expect(lines.map((l) => `${l.kind}:${l.name}`)).toEqual(['provider:db', 'step:user', 'handler:getUser']);
}); });
test('runtime module metadata without mountpoint names module and missing field', () => {
@Route('/broken')
class BrokenCtl {
@Get('/')
get() {
return { ok: true };
}
}
@Module({ mountpoint: '/broken', controllers: [BrokenCtl] })
class BrokenModule {}
const metadata = getModuleMeta(BrokenModule);
if (!metadata) throw new Error('test setup failed');
Object.defineProperty(metadata, 'mountpoint', { value: undefined });
expect(() => createApp({ modules: [BrokenModule] })).toThrow(/BrokenModule.*mountpoint/);
});
test("an empty mountpoint still mounts at the root, as it did before the missing-mountpoint check", async () => {
@Route('/')
class RootCtl {
@Get('/hi')
hi() {
return { ok: true };
}
}
@Module({ mountpoint: '', controllers: [RootCtl] })
class RootModule {}
const res = await createApp({ modules: [RootModule] }).fetch(new Request('http://x/hi'));
expect(res.status).toBe(200);
});
test('ready() is a no-op on a non-mesh app, so one protocol works for both', async () => { test('ready() is a no-op on a non-mesh app, so one protocol works for both', async () => {
// The point: code holding an `App` should not have to know whether it is a mesh app. // The point: code holding an `App` should not have to know whether it is a mesh app.
// `await app.ready(); app.graph()` is uniform — here it changes nothing and boots nothing. // `await app.ready(); app.graph()` is uniform — here it changes nothing and boots nothing.