Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"micro": "9.3.5-canary.3",
"ms": "2.1.1",
"node-fetch": "2.6.7",
"path-match": "1.2.4",
"path-to-regexp": "8.2.0",
"promisepipe": "3.0.0",
"semver": "7.5.4",
"stat-mode": "0.3.0",
Expand Down
42 changes: 7 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions src/runtime-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { parse } from 'node:url';
import createDebug from 'debug';
import { run, text } from 'micro';
import { randomUUID as uuid } from 'node:crypto';
import createPathMatch from 'path-match';
import { match } from 'path-to-regexp';
import once from '@tootallnate/once';

import { createDeferred, Deferred } from './deferred';
import { Lambda, InvokeParams, InvokeResult } from './types';

const pathMatch = createPathMatch();
const match = pathMatch('/:version/runtime/:subject/:target/:action?');
const matchFn = match<{
version: string;
subject: string;
target: string;
action?: string;
}>('/:version/runtime/:subject/:target{/:action}');
const debug = createDebug('@vercel/fun:runtime-server');

function send404(res: http.ServerResponse) {
Expand Down Expand Up @@ -52,12 +56,12 @@ export class RuntimeServer extends Server {
): Promise<any> {
debug('%s %s', req.method, req.url);

const params = match(parse(req.url).pathname);
if (!params) {
const result = matchFn(parse(req.url).pathname);
if (!result) {
return send404(res);
}

const { version, subject, target, action } = params;
const { version, subject, target, action } = result.params;
if (this.version !== version) {
debug(
'Invalid API version, expected %o but got %o',
Expand Down
2 changes: 1 addition & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,4 @@ it(
assert(/^zeit-fun-/.test(basename(env.LAMBDA_TASK_ROOT)));
}
)
);
);