@superfunctions/http 0.1.1 → 0.1.2

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 +45 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -72,12 +72,12 @@ const apiRouter = createRouter({
72
72
 
73
73
  ```typescript
74
74
  import express from 'express';
75
- import { toExpressRouter } from '@superfunctions/http-express';
75
+ import { toExpress } from '@superfunctions/http-express';
76
76
  import { apiRouter } from './api';
77
77
 
78
78
  const app = express();
79
79
  app.use(express.json());
80
- app.use('/api', toExpressRouter(apiRouter));
80
+ app.use('/api', toExpress(apiRouter));
81
81
  app.listen(3000);
82
82
  ```
83
83
 
@@ -85,11 +85,11 @@ app.listen(3000);
85
85
 
86
86
  ```typescript
87
87
  import { Hono } from 'hono';
88
- import { toHonoHandler } from '@superfunctions/http-hono';
88
+ import { toHono } from '@superfunctions/http-hono';
89
89
  import { apiRouter } from './api';
90
90
 
91
91
  const app = new Hono();
92
- app.route('/api', toHonoHandler(apiRouter));
92
+ app.route('/api', toHono(apiRouter));
93
93
 
94
94
  export default app;
95
95
  ```
@@ -105,14 +105,14 @@ const router = createRouter({ routes: [...] });
105
105
 
106
106
  // Cloudflare Workers
107
107
  export default {
108
- fetch: (req) => router.handler(req)
108
+ fetch: router.handle
109
109
  };
110
110
 
111
111
  // Deno
112
- Deno.serve((req) => router.handler(req));
112
+ Deno.serve(router.handle);
113
113
 
114
114
  // Bun
115
- Bun.serve({ fetch: (req) => router.handler(req) });
115
+ Bun.serve({ fetch: router.handle });
116
116
  ```
117
117
 
118
118
  ## Features
@@ -186,6 +186,41 @@ const router = createRouter({
186
186
  });
187
187
  ```
188
188
 
189
+ ### Base Path
190
+
191
+ **⚠️ Important: Only use `basePath` for standalone deployments without framework mounting.**
192
+
193
+ ```typescript
194
+ // ✅ Good: Standalone deployment (Cloudflare Workers, Vercel Edge)
195
+ const router = createRouter({
196
+ basePath: '/api/v1',
197
+ routes: [
198
+ { method: 'GET', path: '/users', handler: ... } // Accessible at /api/v1/users
199
+ ]
200
+ });
201
+
202
+ export default { fetch: router.handle }; // or router.handler
203
+
204
+ // ❌ Bad: With framework mounting (creates double prefixing)
205
+ const router = createRouter({
206
+ basePath: '/v1', // Don't do this!
207
+ routes: [...]
208
+ });
209
+ app.use('/api', toExpress(router)); // Would need /api/v1/users
210
+
211
+ // ✅ Good: With framework mounting (no basePath)
212
+ const router = createRouter({
213
+ routes: [
214
+ { method: 'GET', path: '/users', handler: ... }
215
+ ]
216
+ });
217
+ app.use('/api/v1', toExpress(router)); // Accessible at /api/v1/users
218
+ ```
219
+
220
+ **Rule of thumb:**
221
+ - **Standalone deployment** → Use `basePath` in router
222
+ - **Framework mounting** → Use framework's mounting (e.g., `app.use('/path', ...)`) and omit `basePath`
223
+
189
224
  ### CORS
190
225
 
191
226
  ```typescript
@@ -250,9 +285,9 @@ interface RouteContext {
250
285
 
251
286
  | Framework | Package | Function |
252
287
  |-----------|---------|----------|
253
- | Express | `@superfunctions/http-express` | `toExpressRouter()`, `toExpressHandler()` |
254
- | Hono | `@superfunctions/http-hono` | `toHonoHandler()` |
255
- | Fastify | `@superfunctions/http-fastify` | `toFastifyPlugin()` |
288
+ | Express | `@superfunctions/http-express` | `toExpress()`, `toExpressHandler()` |
289
+ | Hono | `@superfunctions/http-hono` | `toHono()` |
290
+ | Fastify | `@superfunctions/http-fastify` | `toFastify()` |
256
291
  | Next.js | `@superfunctions/http-next` | `toNextHandlers()` |
257
292
  | SvelteKit | `@superfunctions/http-sveltekit` | `toSvelteKitHandler()`, `toSvelteKitHandlers()` |
258
293
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superfunctions/http",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Framework-agnostic HTTP abstraction layer for Superfunctions libraries",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",