({
config,
esm = false,
handler,
path: filePath,
pathPrefix = 'functions',
runtimeAPIVersion,
}: {
config?: object
esm?: boolean
handler: Handler | ((req: Request, context: Context) => Response | Promise<Response>) | string
path: string
pathPrefix?: string
runtimeAPIVersion?: number
})
| 75 | } |
| 76 | |
| 77 | withFunction({ |
| 78 | config, |
| 79 | esm = false, |
| 80 | handler, |
| 81 | path: filePath, |
| 82 | pathPrefix = 'functions', |
| 83 | runtimeAPIVersion, |
| 84 | }: { |
| 85 | config?: object |
| 86 | esm?: boolean |
| 87 | handler: Handler | ((req: Request, context: Context) => Response | Promise<Response>) | string |
| 88 | path: string |
| 89 | pathPrefix?: string |
| 90 | runtimeAPIVersion?: number |
| 91 | }) { |
| 92 | const dest = path.join(this.directory, pathPrefix, filePath) |
| 93 | this.tasks.push(async () => { |
| 94 | await ensureDir(path.dirname(dest)) |
| 95 | |
| 96 | let file = '' |
| 97 | |
| 98 | if (runtimeAPIVersion === 2) { |
| 99 | file = `const handler = ${handler.toString()}; export default handler;` |
| 100 | |
| 101 | if (config) { |
| 102 | file += `export const config = ${inspect(config)};` |
| 103 | } |
| 104 | } else { |
| 105 | file = esm ? `export const handler = ${handler.toString()}` : `exports.handler = ${handler.toString()}` |
| 106 | } |
| 107 | |
| 108 | await writeFile(dest, file) |
| 109 | }) |
| 110 | |
| 111 | return this |
| 112 | } |
| 113 | |
| 114 | withEdgeFunction({ |
| 115 | config, |
no test coverage detected