-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make sure that we can use javascript as an entrypoint (#424)
* chore: make sure that we can use js script as an entrypoint * chore: add js flavored examples * stamp: clippy
- Loading branch information
1 parent
7c378e6
commit 5bd54ed
Showing
8 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { createClient } from "npm:@supabase/[email protected]"; | ||
Deno.serve((_req) => new Response(`${typeof createClient}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Deno.serve(req => { | ||
console.log(req.headers.get("content-type")); | ||
return new Response("meow"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
console.log('main function started'); | ||
|
||
Deno.serve(async (req: Request) => { | ||
console.log(req.url); | ||
const url = new URL(req.url); | ||
const { pathname } = url; | ||
const path_parts = pathname.split("/"); | ||
const service_name = path_parts[1]; | ||
const maybeEszip = new Uint8Array(await req.arrayBuffer()); | ||
|
||
if (!service_name || service_name === "") { | ||
const error = { msg: "missing function name in request" } | ||
return new Response( | ||
JSON.stringify(error), | ||
{ status: 400, headers: { "Content-Type": "application/json" } }, | ||
) | ||
} | ||
|
||
const servicePath = `./test_cases/${service_name}`; | ||
console.error(`serving the request with ${servicePath}`); | ||
|
||
const createWorker = async () => { | ||
const memoryLimitMb = 150; | ||
const workerTimeoutMs = 10 * 60 * 1000; | ||
const cpuTimeSoftLimitMs = 10 * 60 * 1000; | ||
const cpuTimeHardLimitMs = 10 * 60 * 1000; | ||
const noModuleCache = false; | ||
const importMapPath = null; | ||
const envVarsObj = Deno.env.toObject(); | ||
const envVars = Object.keys(envVarsObj).map(k => [k, envVarsObj[k]]); | ||
|
||
return await EdgeRuntime.userWorkers.create({ | ||
servicePath, | ||
memoryLimitMb, | ||
workerTimeoutMs, | ||
cpuTimeSoftLimitMs, | ||
cpuTimeHardLimitMs, | ||
noModuleCache, | ||
importMapPath, | ||
envVars, | ||
maybeEszip | ||
}); | ||
} | ||
|
||
const callWorker = async () => { | ||
try { | ||
const worker = await createWorker(); | ||
return await worker.fetch(req); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
// if (e instanceof Deno.errors.WorkerRequestCancelled) { | ||
// return await callWorker(); | ||
// } | ||
|
||
const error = { msg: e.toString() } | ||
return new Response( | ||
JSON.stringify(error), | ||
{ status: 500, headers: { "Content-Type": "application/json" } }, | ||
); | ||
} | ||
} | ||
|
||
return callWorker(); | ||
}) |
10 changes: 10 additions & 0 deletions
10
crates/base/test_cases/serve-declarative-style-js/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
/** | ||
* @param {Request} req | ||
* @returns {void} | ||
*/ | ||
fetch(req) { | ||
console.log(req.headers.get("content-type")); | ||
return new Response("meow"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Deno.serve(req => { | ||
console.log(req.headers.get("content-type")); | ||
return new Response("meow"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
/** | ||
* @param {Request} req | ||
* @returns {void} | ||
*/ | ||
fetch(req) { | ||
console.log(req.headers.get("content-type")); | ||
return new Response("Hello, world"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Deno.serve(req => { | ||
console.log(req.headers.get("content-type")); | ||
return new Response("Hello, world"); | ||
}); |