@richie-router/server 0.1.8 → 0.1.9

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.
@@ -150,6 +150,46 @@ function createCompetingHeadArtifacts() {
150
150
  headTags
151
151
  };
152
152
  }
153
+ function createUsernameRedirectArtifacts() {
154
+ const rootRoute = import_core.createRouteNode("__root__", {}, { isRoot: true });
155
+ const usernameRoute = import_core.createRouteNode("/$username", {});
156
+ const legacyUsernameRoute = import_core.createRouteNode("/legacy/$username", {});
157
+ usernameRoute._setServerHead(true);
158
+ legacyUsernameRoute._setServerHead(true);
159
+ rootRoute._addFileChildren({
160
+ username: usernameRoute,
161
+ legacyUsername: legacyUsernameRoute
162
+ });
163
+ const routerSchema = import_core.defineRouterSchema({
164
+ "/$username": {
165
+ serverHead: true
166
+ },
167
+ "/legacy/$username": {
168
+ serverHead: true
169
+ }
170
+ });
171
+ const headTags = import__.defineHeadTags(rootRoute, routerSchema, {
172
+ "/$username": {
173
+ head: ({ params }) => [
174
+ { tag: "title", children: `User ${params.username}` }
175
+ ]
176
+ },
177
+ "/legacy/$username": {
178
+ head: ({ params }) => {
179
+ import_core.redirect({
180
+ to: "/$username",
181
+ params: {
182
+ username: params.username
183
+ }
184
+ });
185
+ }
186
+ }
187
+ });
188
+ return {
189
+ routeManifest: rootRoute,
190
+ headTags
191
+ };
192
+ }
153
193
  import_bun_test.describe("handleSpaRequest", () => {
154
194
  import_bun_test.test('treats "/" as the root basePath and trims trailing slashes', () => {
155
195
  const { spaRoutesManifest } = createTestArtifacts();
@@ -308,6 +348,20 @@ import_bun_test.describe("handleRequest basePath", () => {
308
348
  import_bun_test.expect(result.response.status).toBe(302);
309
349
  import_bun_test.expect(result.response.headers.get("location")).toBe("/project");
310
350
  });
351
+ import_bun_test.test("preserves @ in redirect targets built from params", async () => {
352
+ const { routeManifest, headTags } = createUsernameRedirectArtifacts();
353
+ const result = await import__.handleRequest(new Request("https://example.com/project/legacy/%40alice"), {
354
+ routeManifest,
355
+ headTags,
356
+ basePath: "/project",
357
+ html: {
358
+ template: "<html><head><!--richie-router-head--></head><body></body></html>"
359
+ }
360
+ });
361
+ import_bun_test.expect(result.matched).toBe(true);
362
+ import_bun_test.expect(result.response.status).toBe(302);
363
+ import_bun_test.expect(result.response.headers.get("location")).toBe("/project/@alice");
364
+ });
311
365
  import_bun_test.test("uses the basePath for default head API requests handled through handleRequest", async () => {
312
366
  const { routeManifest, headTags } = createTestArtifacts();
313
367
  const result = await import__.handleRequest(new Request("https://example.com/project/head-api?routeId=%2Fabout&params=%7B%7D&search=%7B%7D"), {
@@ -150,6 +150,46 @@ function createCompetingHeadArtifacts() {
150
150
  headTags
151
151
  };
152
152
  }
153
+ function createUsernameRedirectArtifacts() {
154
+ const rootRoute = createRouteNode("__root__", {}, { isRoot: true });
155
+ const usernameRoute = createRouteNode("/$username", {});
156
+ const legacyUsernameRoute = createRouteNode("/legacy/$username", {});
157
+ usernameRoute._setServerHead(true);
158
+ legacyUsernameRoute._setServerHead(true);
159
+ rootRoute._addFileChildren({
160
+ username: usernameRoute,
161
+ legacyUsername: legacyUsernameRoute
162
+ });
163
+ const routerSchema = defineRouterSchema({
164
+ "/$username": {
165
+ serverHead: true
166
+ },
167
+ "/legacy/$username": {
168
+ serverHead: true
169
+ }
170
+ });
171
+ const headTags = defineHeadTags(rootRoute, routerSchema, {
172
+ "/$username": {
173
+ head: ({ params }) => [
174
+ { tag: "title", children: `User ${params.username}` }
175
+ ]
176
+ },
177
+ "/legacy/$username": {
178
+ head: ({ params }) => {
179
+ redirect({
180
+ to: "/$username",
181
+ params: {
182
+ username: params.username
183
+ }
184
+ });
185
+ }
186
+ }
187
+ });
188
+ return {
189
+ routeManifest: rootRoute,
190
+ headTags
191
+ };
192
+ }
153
193
  describe("handleSpaRequest", () => {
154
194
  test('treats "/" as the root basePath and trims trailing slashes', () => {
155
195
  const { spaRoutesManifest } = createTestArtifacts();
@@ -308,6 +348,20 @@ describe("handleRequest basePath", () => {
308
348
  expect(result.response.status).toBe(302);
309
349
  expect(result.response.headers.get("location")).toBe("/project");
310
350
  });
351
+ test("preserves @ in redirect targets built from params", async () => {
352
+ const { routeManifest, headTags } = createUsernameRedirectArtifacts();
353
+ const result = await handleRequest(new Request("https://example.com/project/legacy/%40alice"), {
354
+ routeManifest,
355
+ headTags,
356
+ basePath: "/project",
357
+ html: {
358
+ template: "<html><head><!--richie-router-head--></head><body></body></html>"
359
+ }
360
+ });
361
+ expect(result.matched).toBe(true);
362
+ expect(result.response.status).toBe(302);
363
+ expect(result.response.headers.get("location")).toBe("/project/@alice");
364
+ });
311
365
  test("uses the basePath for default head API requests handled through handleRequest", async () => {
312
366
  const { routeManifest, headTags } = createTestArtifacts();
313
367
  const result = await handleRequest(new Request("https://example.com/project/head-api?routeId=%2Fabout&params=%7B%7D&search=%7B%7D"), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@richie-router/server",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Server helpers for Richie Router head tags and document handling",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -13,7 +13,7 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@richie-router/core": "^0.1.5"
16
+ "@richie-router/core": "^0.1.6"
17
17
  },
18
18
  "author": "Richie <oss@ricsam.dev>",
19
19
  "homepage": "https://docs.ricsam.dev/richie-router",