@sourceregistry/node-webserver 1.2.0 → 1.2.1

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.
Files changed (2) hide show
  1. package/README.md +30 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -120,6 +120,36 @@ app.GET("/message", () => text("plain text"));
120
120
  app.GET("/data", () => json({ ok: true }));
121
121
  ```
122
122
 
123
+ It also exports `redirect()` and `error()` for control flow. These helpers throw a `Response`, and the router immediately returns that response without continuing route resolution. This works in normal routes, middleware, lifecycle hooks, and nested routers.
124
+
125
+ ```ts
126
+ import { error, redirect } from "@sourceregistry/node-webserver";
127
+
128
+ app.GET("/old", () => {
129
+ redirect(302, "/new");
130
+ });
131
+
132
+ app.GET("/admin", (event) => {
133
+ if (!event.locals.userId) {
134
+ error(401, { message: "Unauthorized" });
135
+ }
136
+
137
+ return new Response("secret");
138
+ });
139
+ ```
140
+
141
+ Nested routers short-circuit the same way:
142
+
143
+ ```ts
144
+ const api = new Router();
145
+
146
+ api.GET("/legacy", () => {
147
+ redirect(301, "/api/v2");
148
+ });
149
+
150
+ app.use("/api", api);
151
+ ```
152
+
123
153
  ## Request Handling
124
154
 
125
155
  Route handlers receive a web-standard `Request` plus extra routing data:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourceregistry/node-webserver",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "TypeScript web server for Node.js with web-standard Request and Response APIs",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",