Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd3394d

Browse files
committed
upload
1 parent 152c889 commit fd3394d

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"type": "module",
88
"devDependencies": {
99
"miniflare": "^2.11.0",
10-
"wrangler": "^2.9.0"
10+
"wrangler": "^2.9.0",
11+
"@cloudflare/kv-asset-handler": "^0.3.0"
1112
},
1213
"dependencies": {
1314
"itty-router": "^3.0.11",

src/index.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import { nanoid } from "nanoid";
22
import { Router } from 'itty-router'
3+
import { getAssetFromKV } from '@cloudflare/kv-asset-handler';
4+
import manifestJSON from '__STATIC_CONTENT_MANIFEST';
5+
const assetManifest = JSON.parse(manifestJSON);
36

47
const router = Router()
58

6-
router.get('/', () => new Response(JSON.stringify({ id: nanoid(5) }), {
7-
headers: {
8-
'content-type': 'application/json;charset=UTF-8',
9+
router.get('/', async (request, env, ctx) => {
10+
try {
11+
// Add logic to decide whether to serve an asset or run your original Worker code
12+
return await getAssetFromKV(
13+
{
14+
request,
15+
waitUntil: ctx.waitUntil.bind(ctx),
16+
},
17+
{
18+
ASSET_NAMESPACE: env.__STATIC_CONTENT,
19+
ASSET_MANIFEST: assetManifest,
20+
}
21+
);
22+
} catch (e) {
23+
let pathname = new URL(request.url).pathname;
24+
return new Response(`"${pathname}" not found`, {
25+
status: 404,
26+
statusText: 'not found',
27+
});
928
}
10-
}))
29+
})
1130

1231
router.get('/ws', (request) => {
1332
const upgradeHeader = request.headers.get("Upgrade");
@@ -35,6 +54,12 @@ router.all('*', () => new Response('Not Found.', { status: 404 }))
3554
export default {
3655
async fetch(request, env, ctx) {
3756
return router.handle(request)
38-
}
57+
},
58+
59+
async scheduled(event, env, ctx) {
60+
ctx.waitUntil(() => {
61+
console.log(111)
62+
});
63+
},
3964
}
4065

src/public/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1>hello world</h1>
11+
</body>
12+
</html>

wrangler.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ route = { pattern = "pastes.xiadd.me", custom_domain = true }
1010
kv_namespaces = [
1111
{ binding = "pastes", id = "85ce3453c9f942a6900a5e9e4cdd34e7", preview_id = "54fef46249b4401fa639b1e2cc74e848" }
1212
]
13+
14+
[triggers]
15+
crons = ["*/1 * * * *"]
16+
17+
[site]
18+
bucket = "./src/public"

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
dependencies:
1010
mime "^3.0.0"
1111

12+
"@cloudflare/kv-asset-handler@^0.3.0":
13+
version "0.3.0"
14+
resolved "https://registry.yarnpkg.com/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.3.0.tgz#11f0af0749a400ddadcca16dcd6f4696d7036991"
15+
integrity sha512-9CB/MKf/wdvbfkUdfrj+OkEwZ5b7rws0eogJ4293h+7b6KX5toPwym+VQKmILafNB9YiehqY0DlNrDcDhdWHSQ==
16+
dependencies:
17+
mime "^3.0.0"
18+
1219
"@esbuild-plugins/node-globals-polyfill@^0.1.1":
1320
version "0.1.1"
1421
resolved "https://registry.yarnpkg.com/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.1.1.tgz#a313ab3efbb2c17c8ce376aa216c627c9b40f9d7"

0 commit comments

Comments
 (0)