first commit
This commit is contained in:
commit
230feecf5e
|
|
@ -0,0 +1 @@
|
||||||
|
dist
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Pacifico&display=swap" rel="stylesheet">
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
h1 {
|
||||||
|
font-family: Pacifico, sans-serif;
|
||||||
|
font-size: 4em;
|
||||||
|
color: #3eb5f1;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-weight: 300;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
position: fixed;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ferris {
|
||||||
|
width: 75%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="centered">
|
||||||
|
<h1>404 Not Found</h1>
|
||||||
|
<h2>Oh dang! We couldn't find that page.</h2>
|
||||||
|
<img id="ferris" alt="a sad crab is unable to unable to lasso a paper airplane. 404 not found." src="./img/404-wrangler-ferris.gif">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
|
|
@ -0,0 +1,40 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Pacifico&display=swap" rel="stylesheet">
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
h1 {
|
||||||
|
font-family: Pacifico, sans-serif;
|
||||||
|
font-size: 4em;
|
||||||
|
color: #3eb5f1;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-weight: 300;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
position: fixed;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ferris {
|
||||||
|
width: 75%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="centered">
|
||||||
|
<h1>200 Success</h1>
|
||||||
|
<h2>Hello World! Welcome to your Workers Site.</h2>
|
||||||
|
<img id="ferris" alt="a happy crab is wearing a cowboy hat and holding a lasso. 200 success." src="./img/200-wrangler-ferris.gif">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
worker
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DEBUG flag will do two things that help during development:
|
||||||
|
* 1. we will skip caching on the edge, which makes it easier to
|
||||||
|
* debug.
|
||||||
|
* 2. we will return an error message on exception in your Response rather
|
||||||
|
* than the default 404.html page.
|
||||||
|
*/
|
||||||
|
const DEBUG = false
|
||||||
|
|
||||||
|
addEventListener('fetch', event => {
|
||||||
|
event.respondWith(handleEvent(event))
|
||||||
|
})
|
||||||
|
|
||||||
|
async function handleEvent(event) {
|
||||||
|
let options = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can add custom logic to how we fetch your assets
|
||||||
|
* by configuring the function `mapRequestToAsset`
|
||||||
|
*/
|
||||||
|
// options.mapRequestToAsset = handlePrefix(/^\/docs/)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (DEBUG) {
|
||||||
|
// customize caching
|
||||||
|
options.cacheControl = {
|
||||||
|
bypassCache: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = await getAssetFromKV(event, options)
|
||||||
|
|
||||||
|
// allow headers to be altered
|
||||||
|
const response = new Response(page.body, page)
|
||||||
|
|
||||||
|
response.headers.set('X-XSS-Protection', '1; mode=block')
|
||||||
|
response.headers.set('X-Content-Type-Options', 'nosniff')
|
||||||
|
response.headers.set('X-Frame-Options', 'DENY')
|
||||||
|
response.headers.set('Referrer-Policy', 'unsafe-url')
|
||||||
|
response.headers.set('Feature-Policy', 'none')
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
// if an error is thrown try to serve the asset at 404.html
|
||||||
|
if (!DEBUG) {
|
||||||
|
try {
|
||||||
|
let notFoundResponse = await getAssetFromKV(event, {
|
||||||
|
mapRequestToAsset: req => new Request(`${new URL(req.url).origin}/404.html`, req),
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(notFoundResponse.body, { ...notFoundResponse, status: 404 })
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(e.message || e.toString(), { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Here's one example of how to modify a request to
|
||||||
|
* remove a specific prefix, in this case `/docs` from
|
||||||
|
* the url. This can be useful if you are deploying to a
|
||||||
|
* route on a zone, or if you only want your static content
|
||||||
|
* to exist at a specific path.
|
||||||
|
*/
|
||||||
|
function handlePrefix(prefix) {
|
||||||
|
return request => {
|
||||||
|
// compute the default (e.g. / -> index.html)
|
||||||
|
let defaultAssetKey = mapRequestToAsset(request)
|
||||||
|
let url = new URL(defaultAssetKey.url)
|
||||||
|
|
||||||
|
// strip the prefix from the path for lookup
|
||||||
|
url.pathname = url.pathname.replace(prefix, '/')
|
||||||
|
|
||||||
|
// inherit all other props from the default request
|
||||||
|
return new Request(url.toString(), defaultAssetKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@cloudflare/kv-asset-handler": {
|
||||||
|
"version": "0.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.1.2.tgz",
|
||||||
|
"integrity": "sha512-otES1gV5mEhNh82p/sJERPMMrC7UOLV2JyfKf4e3EX1TmMkZ3N8IDGAqRNsoRU8UYTO7wc83I7pH1p4ozAdgMQ==",
|
||||||
|
"requires": {
|
||||||
|
"mime": "^2.5.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mime": {
|
||||||
|
"version": "2.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime/-/mime-2.5.2.tgz",
|
||||||
|
"integrity": "sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A template for kick starting a Cloudflare Workers project",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@cloudflare/kv-asset-handler": "~0.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
account_id = ""
|
||||||
|
name = "velvox-dev"
|
||||||
|
type = "webpack"
|
||||||
|
workers_dev = true
|
||||||
|
site = { bucket = "./public" }
|
||||||
|
compatibility_date = "2022-01-22"
|
||||||
Loading…
Reference in New Issue