68
loading...
This website collects cookies to deliver better user experience
index.js
file for our function which will respond to all incoming HTTP requests with plain text and a 200 OK
HTTP status.touch index.js
FetchEvent
API used in Service Workers.// index.js
addEventListener("fetch", (event) => {
event.respondWith(
new Response("ajcwebdev-deno", {
status: 200,
headers: {
"content-type": "text/plain"
},
}),
)
})
addEventListener
, with the event type fetch
. The second parameter provided to addEventListener
is a callback that is called with a FetchEvent
property for every request.git init
git add .
git commit -m "Just a denonstration"
git remote add origin https://github.com/ajcwebdev/ajcwebdev-deno.git
git push -u origin main
content-type
to text/html
and include an <h2>
header in the Response
.// index.js
addEventListener("fetch", (event) => {
event.respondWith(
new Response("<h2>ajcwebdev-deno</h2>", {
status: 200,
headers: {
"content-type": "text/html"
},
}),
)
})
.jsx
or .tsx
file extensions for Deno Deploy to transform JSX code.mv index.js index.jsx
h
factory function instead of React.createElement
. renderToString
generates an html string from JSX components.// index.jsx
import { h } from "https://x.lcas.dev/[email protected]/mod.js"
import { renderToString } from "https://x.lcas.dev/[email protected]/ssr.js"
function App() {
return (
<html>
<head>
<title>ajcwebdev-deno</title>
</head>
<body>
<h1>ajcwebdev-deno</h1>
</body>
</html>
)
}
addEventListener("fetch", (event) => {
const response = new Response(
renderToString(<App />), {
headers: {
"content-type": "text/html; charset=utf-8"
},
}
)
event.respondWith(response)
})
deployctl
you can run your Deno Deploy scripts on your local machine. Your scripts are run in the Deno CLI, with the correct TypeScript types for Deno Deploy.deno install \
--allow-read \
--allow-write \
--allow-env \
--allow-net \
--allow-run \
--no-check \
--force \
https://deno.land/x/deploy/deployctl.ts
PATH
variable as seen below but with your own path to the deno
excecutable in place of /Users/ajcwebdev
.export PATH="/Users/ajcwebdev/.deno/bin:$PATH"
--no-check
so TypeScript doesn't explode in a giant fireball of errors.deployctl run \
https://raw.githubusercontent.com/ajcwebdev/ajcwebdev-deno/master/index.jsx \
--no-check
Listening on http://0.0.0.0:8080
--watch
flag to automatically restart the script when any modules in the module graph change.deployctl run \
https://raw.githubusercontent.com/ajcwebdev/ajcwebdev-deno/master/index.jsx \
--no-check \
--watch