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

Function apiRoutePathForFile

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

Source from the content-addressed store, hash-verified

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

Callers 1

extractFunction · 0.85

Calls 3

mapMethod · 0.80
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected