MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / apiRoutePathForFile

Function apiRoutePathForFile

src/resolution/frameworks/expo-router.ts:89–100  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

87 * client's `fetch('/blog/og-image/…')` can find it. Null for any other file.
88 */
89export function apiRoutePathForFile(filePath: string): string | null {
90 const dir = APP_DIR.exec(filePath);
91 if (!dir) return null;
92 const rel = filePath.slice(dir.index + dir[0].length);
93 const ext = /\.(tsx|ts|jsx|js|mjs|cjs)$/.exec(rel);
94 if (!ext) return null;
95 const bare = rel.slice(0, ext.index);
96 if (!bare.endsWith('+api')) return null;
97 const segs = bare.slice(0, -'+api'.length).split('/').filter((seg) => seg.length > 0 && !(seg.startsWith('(') && seg.endsWith(')')));
98 if (segs[segs.length - 1] === 'index') segs.pop();
99 return '/' + segs.map((seg) => seg.replace(/^\[\.\.\.(.+)\]$/, ':$1*').replace(/^\[(.+)\]$/, ':$1')).join('/');
100}
101
102const API_METHODS = 'GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS';
103

Callers 1

extractFunction · 0.85

Calls 3

mapMethod · 0.80
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected