1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export function getFunctionComment(fn) {
try {
return fn.toString().match(/\/\*\s*(.+)\s*\*\//s)[1];
} catch (err) {
console.error(`Failed to get function comment: ${err.message}\n${fn.toString()}`);
throw err;
}
}
export function serve(fn, contentType = 'text/plain') {
return (ctx) => {
return new Response(getFunctionComment(fn), {
headers: {
'Content-Type': contentType,
'Cache-Control': 'no-cache',
},
});
};
}