@trpc/server 11.22.2-canary.16.ea96ec538 → 11.22.2-canary.19.b9321728b

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.
@@ -15,13 +15,19 @@ http = require_rolldown_runtime.__toESM(http, 1);
15
15
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
16
16
  * ```
17
17
  */
18
+ const trimSlashes = (path) => {
19
+ path = path.startsWith("/") ? path.slice(1) : path;
20
+ path = path.endsWith("/") ? path.slice(0, -1) : path;
21
+ return path;
22
+ };
18
23
  function createHandler(opts) {
19
24
  var _opts$basePath;
20
- const sliceLength = ((_opts$basePath = opts.basePath) !== null && _opts$basePath !== void 0 ? _opts$basePath : "/").length;
25
+ const basePath = trimSlashes((_opts$basePath = opts.basePath) !== null && _opts$basePath !== void 0 ? _opts$basePath : "/");
21
26
  return (req, res) => {
22
27
  let path = "";
23
28
  require_codes.run(async () => {
24
- path = require_node_http.createURL(req).pathname.slice(sliceLength);
29
+ const url = require_node_http.createURL(req);
30
+ path = trimSlashes(trimSlashes(url.pathname).slice(basePath.length));
25
31
  await require_node_http.nodeHTTPRequestHandler(require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, opts), {}, {
26
32
  req,
27
33
  res,
@@ -7,7 +7,6 @@ type StandaloneHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHT
7
7
  /**
8
8
  * The base path to handle requests for.
9
9
  * This will be sliced from the beginning of the request path
10
- * (Do not miss including the trailing slash)
11
10
  * @default '/'
12
11
  * @example '/trpc/'
13
12
  * @example '/trpc/api/'
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.d.cts","names":[],"sources":["../../src/adapters/standalone.ts"],"mappings":";;;;;KA6BK,yBACH,gBAAgB,WAChB,iBAAiB,iBACjB,kBAAkB,oBAChB,uBAAuB,SAAS,UAAU;;;;;;;;;EAS5C;;YAIU,yBAAyB,gBAAgB,aACnD,yBAAyB,SAAS,KAAK,iBAAiB,KAAK;YAEnD,2BAA2B,+BACrC,KAAK,iBACL,KAAK;;;;wBA0CS,kBAAkB,gBAAgB,WAChD,MAAM,yBAAyB,WAC9B,KAAK;wBAIQ,iBAAiB,gBAAgB,WAC/C,MAAM,yBAAyB,WAAQ,KAAA,cAAA,KAAA,wBAAA,KAAA;YAM7B,0BAA0B,gBAAgB,aACpD,yBACE,SACA,MAAM,oBACN,MAAM;YAGE,4BAA4B,+BACtC,MAAM,oBACN,MAAM;wBAGQ,mBAAmB,MAAM,0BAA0B,cAAU,KAAA,MAAA,oBAAA,KAAA,MAAA,oBAAA,MAAA"}
1
+ {"version":3,"file":"standalone.d.cts","names":[],"sources":["../../src/adapters/standalone.ts"],"mappings":";;;;;KAqCK,yBACH,gBAAgB,WAChB,iBAAiB,iBACjB,kBAAkB,oBAChB,uBAAuB,SAAS,UAAU;;;;;;;;EAQ5C;;YAIU,yBAAyB,gBAAgB,aACnD,yBAAyB,SAAS,KAAK,iBAAiB,KAAK;YAEnD,2BAA2B,+BACrC,KAAK,iBACL,KAAK;;;;wBAyCS,kBAAkB,gBAAgB,WAChD,MAAM,yBAAyB,WAC9B,KAAK;wBAIQ,iBAAiB,gBAAgB,WAC/C,MAAM,yBAAyB,WAAQ,KAAA,cAAA,KAAA,wBAAA,KAAA;YAM7B,0BAA0B,gBAAgB,aACpD,yBACE,SACA,MAAM,oBACN,MAAM;YAGE,4BAA4B,+BACtC,MAAM,oBACN,MAAM;wBAGQ,mBAAmB,MAAM,0BAA0B,cAAU,KAAA,MAAA,oBAAA,KAAA,MAAA,oBAAA,MAAA"}
@@ -7,7 +7,6 @@ type StandaloneHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHT
7
7
  /**
8
8
  * The base path to handle requests for.
9
9
  * This will be sliced from the beginning of the request path
10
- * (Do not miss including the trailing slash)
11
10
  * @default '/'
12
11
  * @example '/trpc/'
13
12
  * @example '/trpc/api/'
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.d.mts","names":[],"sources":["../../src/adapters/standalone.ts"],"mappings":";;;;;KA6BK,yBACH,gBAAgB,WAChB,iBAAiB,iBACjB,kBAAkB,oBAChB,uBAAuB,SAAS,UAAU;;;;;;;;;EAS5C;;YAIU,yBAAyB,gBAAgB,aACnD,yBAAyB,SAAS,KAAK,iBAAiB,KAAK;YAEnD,2BAA2B,+BACrC,KAAK,iBACL,KAAK;;;;wBA0CS,kBAAkB,gBAAgB,WAChD,MAAM,yBAAyB,WAC9B,KAAK;wBAIQ,iBAAiB,gBAAgB,WAC/C,MAAM,yBAAyB,WAAQ,KAAA,cAAA,KAAA,wBAAA,KAAA;YAM7B,0BAA0B,gBAAgB,aACpD,yBACE,SACA,MAAM,oBACN,MAAM;YAGE,4BAA4B,+BACtC,MAAM,oBACN,MAAM;wBAGQ,mBAAmB,MAAM,0BAA0B,cAAU,KAAA,MAAA,oBAAA,KAAA,MAAA,oBAAA,MAAA"}
1
+ {"version":3,"file":"standalone.d.mts","names":[],"sources":["../../src/adapters/standalone.ts"],"mappings":";;;;;KAqCK,yBACH,gBAAgB,WAChB,iBAAiB,iBACjB,kBAAkB,oBAChB,uBAAuB,SAAS,UAAU;;;;;;;;EAQ5C;;YAIU,yBAAyB,gBAAgB,aACnD,yBAAyB,SAAS,KAAK,iBAAiB,KAAK;YAEnD,2BAA2B,+BACrC,KAAK,iBACL,KAAK;;;;wBAyCS,kBAAkB,gBAAgB,WAChD,MAAM,yBAAyB,WAC9B,KAAK;wBAIQ,iBAAiB,gBAAgB,WAC/C,MAAM,yBAAyB,WAAQ,KAAA,cAAA,KAAA,wBAAA,KAAA;YAM7B,0BAA0B,gBAAgB,aACpD,yBACE,SACA,MAAM,oBACN,MAAM;YAGE,4BAA4B,+BACtC,MAAM,oBACN,MAAM;wBAGQ,mBAAmB,MAAM,0BAA0B,cAAU,KAAA,MAAA,oBAAA,KAAA,MAAA,oBAAA,MAAA"}
@@ -12,13 +12,19 @@ import http from "http";
12
12
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
13
13
  * ```
14
14
  */
15
+ const trimSlashes = (path) => {
16
+ path = path.startsWith("/") ? path.slice(1) : path;
17
+ path = path.endsWith("/") ? path.slice(0, -1) : path;
18
+ return path;
19
+ };
15
20
  function createHandler(opts) {
16
21
  var _opts$basePath;
17
- const sliceLength = ((_opts$basePath = opts.basePath) !== null && _opts$basePath !== void 0 ? _opts$basePath : "/").length;
22
+ const basePath = trimSlashes((_opts$basePath = opts.basePath) !== null && _opts$basePath !== void 0 ? _opts$basePath : "/");
18
23
  return (req, res) => {
19
24
  let path = "";
20
25
  run(async () => {
21
- path = createURL(req).pathname.slice(sliceLength);
26
+ const url = createURL(req);
27
+ path = trimSlashes(trimSlashes(url.pathname).slice(basePath.length));
22
28
  await nodeHTTPRequestHandler(_objectSpread2(_objectSpread2({}, opts), {}, {
23
29
  req,
24
30
  res,
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.mjs","names":[],"sources":["../../src/adapters/standalone.ts"],"sourcesContent":["/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\n\nimport http from 'http';\n// --- http2 ---\nimport type * as http2 from 'http2';\n// @trpc/server\nimport { type AnyRouter } from '../@trpc/server';\n// oxlint-disable-next-line no-restricted-imports\nimport { run } from '../unstable-core-do-not-import';\nimport type {\n NodeHTTPCreateContextFnOptions,\n NodeHTTPHandlerOptions,\n NodeHTTPRequest,\n NodeHTTPResponse,\n} from './node-http';\nimport {\n createURL,\n internal_exceptionHandler,\n nodeHTTPRequestHandler,\n} from './node-http';\n\ntype StandaloneHandlerOptions<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n> = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {\n /**\n * The base path to handle requests for.\n * This will be sliced from the beginning of the request path\n * (Do not miss including the trailing slash)\n * @default '/'\n * @example '/trpc/'\n * @example '/trpc/api/'\n */\n basePath?: string;\n};\n\n// --- http1 ---\nexport type CreateHTTPHandlerOptions<TRouter extends AnyRouter> =\n StandaloneHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;\n\nexport type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<\n http.IncomingMessage,\n http.ServerResponse\n>;\n\nfunction createHandler<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n>(\n opts: StandaloneHandlerOptions<TRouter, TRequest, TResponse>,\n): (req: TRequest, res: TResponse) => void {\n const basePath = opts.basePath ?? '/';\n const sliceLength = basePath.length;\n\n return (req, res) => {\n let path = '';\n\n run(async () => {\n const url = createURL(req);\n\n // get procedure(s) path and remove the leading slash\n path = url.pathname.slice(sliceLength);\n\n await nodeHTTPRequestHandler({\n ...opts,\n req,\n res,\n path,\n });\n }).catch(\n internal_exceptionHandler({\n req,\n res,\n path,\n ...opts,\n }),\n );\n };\n}\n\n/**\n * @internal\n */\nexport function createHTTPHandler<TRouter extends AnyRouter>(\n opts: CreateHTTPHandlerOptions<TRouter>,\n): http.RequestListener {\n return createHandler(opts);\n}\n\nexport function createHTTPServer<TRouter extends AnyRouter>(\n opts: CreateHTTPHandlerOptions<TRouter>,\n) {\n return http.createServer(createHTTPHandler(opts));\n}\n\n// --- http2 ---\nexport type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> =\n StandaloneHandlerOptions<\n TRouter,\n http2.Http2ServerRequest,\n http2.Http2ServerResponse\n >;\n\nexport type CreateHTTP2ContextOptions = NodeHTTPCreateContextFnOptions<\n http2.Http2ServerRequest,\n http2.Http2ServerResponse\n>;\n\nexport function createHTTP2Handler(opts: CreateHTTP2HandlerOptions<AnyRouter>) {\n return createHandler(opts);\n}\n"],"mappings":";;;;;;;;;;;;;;AAsDA,SAAS,cAKP,MACyC;;CAEzC,MAAM,gBAAA,iBADW,KAAK,cAAA,QAAA,mBAAA,KAAA,IAAA,iBAAY,IAAA,CACL;CAE7B,QAAQ,KAAK,QAAQ;EACnB,IAAI,OAAO;EAEX,IAAI,YAAY;GAId,OAHY,UAAU,GAGb,CAAC,CAAC,SAAS,MAAM,WAAW;GAErC,MAAM,uBAAA,eAAA,eAAA,CAAA,GACD,IAAA,GAAA,CAAA,GAAA;IACH;IACA;IACA;GACF,CAAA,CAAC;EACH,CAAC,CAAC,CAAC,MACD,0BAAA,eAAA;GACE;GACA;GACA;EACG,GAAA,IACL,CAAC,CACH;CACF;AACF;;;;AAKA,SAAgB,kBACd,MACsB;CACtB,OAAO,cAAc,IAAI;AAC3B;AAEA,SAAgB,iBACd,MACA;CACA,OAAO,KAAK,aAAa,kBAAkB,IAAI,CAAC;AAClD;AAeA,SAAgB,mBAAmB,MAA4C;CAC7E,OAAO,cAAc,IAAI;AAC3B"}
1
+ {"version":3,"file":"standalone.mjs","names":[],"sources":["../../src/adapters/standalone.ts"],"sourcesContent":["/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\n\nimport http from 'http';\n// --- http2 ---\nimport type * as http2 from 'http2';\n// @trpc/server\nimport { type AnyRouter } from '../@trpc/server';\n// oxlint-disable-next-line no-restricted-imports\nimport { run } from '../unstable-core-do-not-import';\nimport type {\n NodeHTTPCreateContextFnOptions,\n NodeHTTPHandlerOptions,\n NodeHTTPRequest,\n NodeHTTPResponse,\n} from './node-http';\nimport {\n createURL,\n internal_exceptionHandler,\n nodeHTTPRequestHandler,\n} from './node-http';\n\n// same as in the fetch adapter\nconst trimSlashes = (path: string): string => {\n path = path.startsWith('/') ? path.slice(1) : path;\n path = path.endsWith('/') ? path.slice(0, -1) : path;\n\n return path;\n};\n\ntype StandaloneHandlerOptions<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n> = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {\n /**\n * The base path to handle requests for.\n * This will be sliced from the beginning of the request path\n * @default '/'\n * @example '/trpc/'\n * @example '/trpc/api/'\n */\n basePath?: string;\n};\n\n// --- http1 ---\nexport type CreateHTTPHandlerOptions<TRouter extends AnyRouter> =\n StandaloneHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;\n\nexport type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<\n http.IncomingMessage,\n http.ServerResponse\n>;\n\nfunction createHandler<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n>(\n opts: StandaloneHandlerOptions<TRouter, TRequest, TResponse>,\n): (req: TRequest, res: TResponse) => void {\n const basePath = trimSlashes(opts.basePath ?? '/');\n\n return (req, res) => {\n let path = '';\n\n run(async () => {\n const url = createURL(req);\n\n // get procedure(s) path and remove the slashes around it\n path = trimSlashes(trimSlashes(url.pathname).slice(basePath.length));\n\n await nodeHTTPRequestHandler({\n ...opts,\n req,\n res,\n path,\n });\n }).catch(\n internal_exceptionHandler({\n req,\n res,\n path,\n ...opts,\n }),\n );\n };\n}\n\n/**\n * @internal\n */\nexport function createHTTPHandler<TRouter extends AnyRouter>(\n opts: CreateHTTPHandlerOptions<TRouter>,\n): http.RequestListener {\n return createHandler(opts);\n}\n\nexport function createHTTPServer<TRouter extends AnyRouter>(\n opts: CreateHTTPHandlerOptions<TRouter>,\n) {\n return http.createServer(createHTTPHandler(opts));\n}\n\n// --- http2 ---\nexport type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> =\n StandaloneHandlerOptions<\n TRouter,\n http2.Http2ServerRequest,\n http2.Http2ServerResponse\n >;\n\nexport type CreateHTTP2ContextOptions = NodeHTTPCreateContextFnOptions<\n http2.Http2ServerRequest,\n http2.Http2ServerResponse\n>;\n\nexport function createHTTP2Handler(opts: CreateHTTP2HandlerOptions<AnyRouter>) {\n return createHandler(opts);\n}\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,eAAe,SAAyB;CAC5C,OAAO,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI;CAC9C,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI;CAEhD,OAAO;AACT;AA0BA,SAAS,cAKP,MACyC;;CACzC,MAAM,WAAW,aAAA,iBAAY,KAAK,cAAA,QAAA,mBAAA,KAAA,IAAA,iBAAY,GAAG;CAEjD,QAAQ,KAAK,QAAQ;EACnB,IAAI,OAAO;EAEX,IAAI,YAAY;GACd,MAAM,MAAM,UAAU,GAAG;GAGzB,OAAO,YAAY,YAAY,IAAI,QAAQ,CAAC,CAAC,MAAM,SAAS,MAAM,CAAC;GAEnE,MAAM,uBAAA,eAAA,eAAA,CAAA,GACD,IAAA,GAAA,CAAA,GAAA;IACH;IACA;IACA;GACF,CAAA,CAAC;EACH,CAAC,CAAC,CAAC,MACD,0BAAA,eAAA;GACE;GACA;GACA;EACG,GAAA,IACL,CAAC,CACH;CACF;AACF;;;;AAKA,SAAgB,kBACd,MACsB;CACtB,OAAO,cAAc,IAAI;AAC3B;AAEA,SAAgB,iBACd,MACA;CACA,OAAO,KAAK,aAAa,kBAAkB,IAAI,CAAC;AAClD;AAeA,SAAgB,mBAAmB,MAA4C;CAC7E,OAAO,cAAc,IAAI;AAC3B"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@trpc/server",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "11.22.2-canary.16.ea96ec538",
5
+ "version": "11.22.2-canary.19.b9321728b",
6
6
  "description": "The tRPC server library",
7
7
  "author": "KATT",
8
8
  "license": "MIT",
@@ -251,5 +251,5 @@
251
251
  "optional": true
252
252
  }
253
253
  },
254
- "gitHead": "ea96ec538fd7710ee79930bdd6fc16a2a702afaf"
254
+ "gitHead": "b9321728b5ce18f45ec92782a085a10c765e3466"
255
255
  }
@@ -27,6 +27,14 @@ import {
27
27
  nodeHTTPRequestHandler,
28
28
  } from './node-http';
29
29
 
30
+ // same as in the fetch adapter
31
+ const trimSlashes = (path: string): string => {
32
+ path = path.startsWith('/') ? path.slice(1) : path;
33
+ path = path.endsWith('/') ? path.slice(0, -1) : path;
34
+
35
+ return path;
36
+ };
37
+
30
38
  type StandaloneHandlerOptions<
31
39
  TRouter extends AnyRouter,
32
40
  TRequest extends NodeHTTPRequest,
@@ -35,7 +43,6 @@ type StandaloneHandlerOptions<
35
43
  /**
36
44
  * The base path to handle requests for.
37
45
  * This will be sliced from the beginning of the request path
38
- * (Do not miss including the trailing slash)
39
46
  * @default '/'
40
47
  * @example '/trpc/'
41
48
  * @example '/trpc/api/'
@@ -59,8 +66,7 @@ function createHandler<
59
66
  >(
60
67
  opts: StandaloneHandlerOptions<TRouter, TRequest, TResponse>,
61
68
  ): (req: TRequest, res: TResponse) => void {
62
- const basePath = opts.basePath ?? '/';
63
- const sliceLength = basePath.length;
69
+ const basePath = trimSlashes(opts.basePath ?? '/');
64
70
 
65
71
  return (req, res) => {
66
72
  let path = '';
@@ -68,8 +74,8 @@ function createHandler<
68
74
  run(async () => {
69
75
  const url = createURL(req);
70
76
 
71
- // get procedure(s) path and remove the leading slash
72
- path = url.pathname.slice(sliceLength);
77
+ // get procedure(s) path and remove the slashes around it
78
+ path = trimSlashes(trimSlashes(url.pathname).slice(basePath.length));
73
79
 
74
80
  await nodeHTTPRequestHandler({
75
81
  ...opts,