wrangler 0.0.0-e88a54e → 0.0.0-e8df68ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +46 -15
- package/bin/wrangler.js +118 -32
- package/kv-asset-handler.js +1 -0
- package/package.json +194 -143
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +23 -0
- package/templates/facade.d.ts +17 -0
- package/templates/gitignore +172 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +67 -0
- package/templates/middleware/loader-modules.ts +127 -0
- package/templates/middleware/loader-sw.ts +228 -0
- package/templates/middleware/middleware-d1-beta.d.ts +3 -0
- package/templates/middleware/middleware-d1-beta.ts +244 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
- package/templates/middleware/middleware-multiworker-dev.ts +59 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +22 -4
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +55 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +190 -0
- package/templates/pages-template-worker.ts +198 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +6 -103
- package/wrangler-dist/cli.d.ts +1726 -0
- package/wrangler-dist/cli.js +134048 -126481
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/miniflare-dist/index.mjs +0 -79
- package/miniflare-dist/index.mjs.map +0 -7
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -223
- package/pages/functions/filepath-routing.ts +0 -181
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/configuration.test.ts +0 -2796
- package/src/__tests__/dev.test.tsx +0 -496
- package/src/__tests__/dev2.test.tsx +0 -154
- package/src/__tests__/guess-worker-format.test.ts +0 -58
- package/src/__tests__/helpers/clipboardy-mock.js +0 -4
- package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-account-id.ts +0 -48
- package/src/__tests__/helpers/mock-bin.ts +0 -36
- package/src/__tests__/helpers/mock-cfetch.ts +0 -207
- package/src/__tests__/helpers/mock-console.ts +0 -70
- package/src/__tests__/helpers/mock-dialogs.ts +0 -65
- package/src/__tests__/helpers/mock-kv.ts +0 -33
- package/src/__tests__/helpers/mock-stdin.ts +0 -103
- package/src/__tests__/helpers/mock-web-socket.ts +0 -29
- package/src/__tests__/helpers/run-in-tmp.ts +0 -32
- package/src/__tests__/helpers/run-wrangler.ts +0 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
- package/src/__tests__/https-options.test.ts +0 -127
- package/src/__tests__/index.test.ts +0 -991
- package/src/__tests__/jest.setup.ts +0 -69
- package/src/__tests__/kv.test.ts +0 -1382
- package/src/__tests__/logout.test.ts +0 -52
- package/src/__tests__/package-manager.test.ts +0 -206
- package/src/__tests__/pages.test.ts +0 -44
- package/src/__tests__/parse.test.ts +0 -322
- package/src/__tests__/publish.test.ts +0 -2704
- package/src/__tests__/r2.test.ts +0 -198
- package/src/__tests__/route.test.ts +0 -45
- package/src/__tests__/secret.test.ts +0 -425
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/__tests__/tail.test.ts +0 -564
- package/src/__tests__/whoami.test.tsx +0 -100
- package/src/bundle.ts +0 -142
- package/src/cfetch/index.ts +0 -104
- package/src/cfetch/internal.ts +0 -139
- package/src/cli.ts +0 -19
- package/src/config/README.md +0 -107
- package/src/config/config.ts +0 -218
- package/src/config/diagnostics.ts +0 -80
- package/src/config/environment.ts +0 -366
- package/src/config/index.ts +0 -62
- package/src/config/validation-helpers.ts +0 -486
- package/src/config/validation.ts +0 -1090
- package/src/create-worker-preview.ts +0 -166
- package/src/create-worker-upload-form.ts +0 -217
- package/src/dev/dev.tsx +0 -364
- package/src/dev/local.tsx +0 -232
- package/src/dev/remote.tsx +0 -203
- package/src/dev/use-esbuild.ts +0 -100
- package/src/dialogs.tsx +0 -77
- package/src/entry.ts +0 -208
- package/src/environment-variables.ts +0 -33
- package/src/https-options.ts +0 -122
- package/src/index.tsx +0 -2373
- package/src/inspect.ts +0 -617
- package/src/kv.ts +0 -319
- package/src/miniflare-cli/README.md +0 -30
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/miniflare-cli/index.ts +0 -37
- package/src/module-collection.ts +0 -258
- package/src/open-in-browser.ts +0 -25
- package/src/package-manager.ts +0 -126
- package/src/pages.tsx +0 -1047
- package/src/parse.ts +0 -183
- package/src/paths.ts +0 -26
- package/src/proxy.ts +0 -440
- package/src/publish.ts +0 -347
- package/src/r2.ts +0 -50
- package/src/reporting.ts +0 -131
- package/src/selfsigned.d.ts +0 -29
- package/src/sites.tsx +0 -280
- package/src/tail/filters.ts +0 -279
- package/src/tail/index.ts +0 -299
- package/src/tail/printing.ts +0 -62
- package/src/user.tsx +0 -1118
- package/src/whoami.tsx +0 -69
- package/src/worker.ts +0 -163
- package/templates/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2018 Ashley Williams <ashley666ashley@gmail.com>
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any
|
|
4
|
-
person obtaining a copy of this software and associated
|
|
5
|
-
documentation files (the "Software"), to deal in the
|
|
6
|
-
Software without restriction, including without
|
|
7
|
-
limitation the rights to use, copy, modify, merge,
|
|
8
|
-
publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software
|
|
10
|
-
is furnished to do so, subject to the following
|
|
11
|
-
conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice
|
|
14
|
-
shall be included in all copies or substantial portions
|
|
15
|
-
of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
18
|
-
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
20
|
-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
21
|
-
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
24
|
-
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
25
|
-
DEALINGS IN THE SOFTWARE.
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
# @cloudflare/kv-asset-handler
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@cloudflare/kv-asset-handler)
|
|
4
|
-
[](https://github.com/cloudflare/kv-asset-handler/actions/workflows/test.yml)
|
|
5
|
-
[](https://github.com/cloudflare/kv-asset-handler/actions/workflows/lint.yml)
|
|
6
|
-
|
|
7
|
-
`kv-asset-handler` is an open-source library for managing the retrieval of static assets from [Workers KV](https://developers.cloudflare.com/workers/runtime-apis/kv) inside of a [Cloudflare Workers](https://workers.dev) function. `kv-asset-handler` is designed for use with [Workers Sites](https://developers.cloudflare.com/workers/platform/sites), a feature included in [Wrangler](https://github.com/cloudflare/wrangler), our command-line tool for deploying Workers projects.
|
|
8
|
-
|
|
9
|
-
`kv-asset-handler` runs as part of a Cloudflare Workers function, so it allows you to customize _how_ and _when_ your static assets are loaded, as well as customize how those assets behave before they're sent to the client.
|
|
10
|
-
|
|
11
|
-
Most users and sites will not need these customizations, and just want to serve their statically built applications. For that simple use-case, you can check out [Cloudflare Pages](https://pages.cloudflare.com), our batteries-included approach to deploying static sites on Cloudflare's edge network. Workers Sites was designed as a precursor to Cloudflare Pages, so check out Pages if you just want to deploy your static site without any special customizations!
|
|
12
|
-
|
|
13
|
-
For users who _do_ want to customize their assets, and want to build complex experiences on top of their static assets, `kv-asset-handler` (and the default [Workers Sites template](https://github.com/cloudflare/worker-sites-template), which is provided for use with Wrangler + Workers Sites) allows you to customize caching behavior, headers, and anything else about how your Workers function loads the static assets for your site stored in Workers KV.
|
|
14
|
-
|
|
15
|
-
The Cloudflare Workers Discord server is an active place where Workers users get help, share feedback, and collaborate on making our platform better. The `#workers-sites` channel in particular is a great place to chat about `kv-asset-handler`, and building cool experiences for your users using these tools! If you have questions, want to share what you're working on, or give feedback, [join us in Discord and say hello](https://discord.gg/cloudflaredev)!
|
|
16
|
-
|
|
17
|
-
- [Installation](#installation)
|
|
18
|
-
- [Usage](#usage)
|
|
19
|
-
- [`getAssetFromKV`](#-getassetfromkv)
|
|
20
|
-
- [Example](#example)
|
|
21
|
-
* [Return](#return)
|
|
22
|
-
* [Optional Arguments](#optional-arguments)
|
|
23
|
-
- [`mapRequestToAsset`](#-maprequesttoasset)
|
|
24
|
-
- [Example](#example-1)
|
|
25
|
-
- [`cacheControl`](#-cachecontrol)
|
|
26
|
-
- [`browserTTL`](#-browserttl)
|
|
27
|
-
- [`edgeTTL`](#-edgettl)
|
|
28
|
-
- [`bypassCache`](#-bypasscache)
|
|
29
|
-
- [`ASSET_NAMESPACE`](#-asset-namespace)
|
|
30
|
-
- [`ASSET_MANIFEST` (optional)](#-asset-manifest---optional)
|
|
31
|
-
|
|
32
|
-
* [Helper functions](#helper-functions)
|
|
33
|
-
- [`mapRequestToAsset`](#-maprequesttoasset-1)
|
|
34
|
-
- [`serveSinglePageApp`](#-servesinglepageapp)
|
|
35
|
-
* [Cache revalidation and etags](#cache-revalidation-and-etags)
|
|
36
|
-
|
|
37
|
-
## Installation
|
|
38
|
-
|
|
39
|
-
Add this package to your `package.json` by running this in the root of your
|
|
40
|
-
project's directory:
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
npm i @cloudflare/kv-asset-handler
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Usage
|
|
47
|
-
|
|
48
|
-
This package was designed to work with [Worker Sites](https://workers.cloudflare.com/sites).
|
|
49
|
-
|
|
50
|
-
## `getAssetFromKV`
|
|
51
|
-
|
|
52
|
-
getAssetFromKV(FetchEvent) => Promise<Response>
|
|
53
|
-
|
|
54
|
-
`getAssetFromKV` is an async function that takes a `FetchEvent` object and returns a `Response` object if the request matches an asset in KV, otherwise it will throw a `KVError`.
|
|
55
|
-
|
|
56
|
-
#### Example
|
|
57
|
-
|
|
58
|
-
This example checks for the existence of a value in KV, and returns it if it's there, and returns a 404 if it is not. It also serves index.html from `/`.
|
|
59
|
-
|
|
60
|
-
### Return
|
|
61
|
-
|
|
62
|
-
`getAssetFromKV` returns a `Promise<Response>` with `Response` being the body of the asset requested.
|
|
63
|
-
|
|
64
|
-
Known errors to be thrown are:
|
|
65
|
-
|
|
66
|
-
- MethodNotAllowedError
|
|
67
|
-
- NotFoundError
|
|
68
|
-
- InternalError
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
import { getAssetFromKV, NotFoundError, MethodNotAllowedError } from '@cloudflare/kv-asset-handler'
|
|
72
|
-
|
|
73
|
-
addEventListener('fetch', (event) => {
|
|
74
|
-
event.respondWith(handleEvent(event))
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
async function handleEvent(event) {
|
|
78
|
-
if (event.request.url.includes('/docs')) {
|
|
79
|
-
try {
|
|
80
|
-
return await getAssetFromKV(event)
|
|
81
|
-
} catch (e) {
|
|
82
|
-
if (e instanceof NotFoundError) {
|
|
83
|
-
// ...
|
|
84
|
-
} else if (e instanceof MethodNotAllowedError) {
|
|
85
|
-
// ...
|
|
86
|
-
} else {
|
|
87
|
-
return new Response('An unexpected error occurred', { status: 500 })
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
} else return fetch(event.request)
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Optional Arguments
|
|
95
|
-
|
|
96
|
-
You can customize the behavior of `getAssetFromKV` by passing the following properties as an object into the second argument.
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
getAssetFromKV(event, { mapRequestToAsset: ... })
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
#### `mapRequestToAsset`
|
|
103
|
-
|
|
104
|
-
mapRequestToAsset(Request) => Request
|
|
105
|
-
|
|
106
|
-
Maps the incoming request to the value that will be looked up in Cloudflare's KV
|
|
107
|
-
|
|
108
|
-
By default, mapRequestToAsset is set to the exported function [`mapRequestToAsset`](#maprequesttoasset-1). This works for most static site generators, but you can customize this behavior by passing your own function as `mapRequestToAsset`. The function should take a `Request` object as its only argument, and return a new `Request` object with an updated path to be looked up in the asset manifest/KV.
|
|
109
|
-
|
|
110
|
-
For SPA mapping pass in the [`serveSinglePageApp`](#servesinglepageapp) function
|
|
111
|
-
|
|
112
|
-
#### Example
|
|
113
|
-
|
|
114
|
-
Strip `/docs` from any incoming request before looking up an asset in Cloudflare's KV.
|
|
115
|
-
|
|
116
|
-
```js
|
|
117
|
-
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'
|
|
118
|
-
...
|
|
119
|
-
const customKeyModifier = request => {
|
|
120
|
-
let url = request.url
|
|
121
|
-
//custom key mapping optional
|
|
122
|
-
url = url.replace('/docs', '').replace(/^\/+/, '')
|
|
123
|
-
return mapRequestToAsset(new Request(url, request))
|
|
124
|
-
}
|
|
125
|
-
let asset = await getAssetFromKV(event, { mapRequestToAsset: customKeyModifier })
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
#### `cacheControl`
|
|
129
|
-
|
|
130
|
-
type: object
|
|
131
|
-
|
|
132
|
-
`cacheControl` allows you to configure options for both the Cloudflare Cache accessed by your Worker, and the browser cache headers sent along with your Workers' responses. The default values are as follows:
|
|
133
|
-
|
|
134
|
-
```javascript
|
|
135
|
-
let cacheControl = {
|
|
136
|
-
browserTTL: null, // do not set cache control ttl on responses
|
|
137
|
-
edgeTTL: 2 * 60 * 60 * 24, // 2 days
|
|
138
|
-
bypassCache: false, // do not bypass Cloudflare's cache
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
##### `browserTTL`
|
|
143
|
-
|
|
144
|
-
type: number | null
|
|
145
|
-
nullable: true
|
|
146
|
-
|
|
147
|
-
Sets the `Cache-Control: max-age` header on the response returned from the Worker. By default set to `null` which will not add the header at all.
|
|
148
|
-
|
|
149
|
-
##### `edgeTTL`
|
|
150
|
-
|
|
151
|
-
type: number | null
|
|
152
|
-
nullable: true
|
|
153
|
-
|
|
154
|
-
Sets the `Cache-Control: max-age` header on the response used as the edge cache key. By default set to 2 days (`2 * 60 * 60 * 24`). When null will not cache on the edge at all.
|
|
155
|
-
|
|
156
|
-
##### `bypassCache`
|
|
157
|
-
|
|
158
|
-
type: boolean
|
|
159
|
-
|
|
160
|
-
Determines whether to cache requests on Cloudflare's edge cache. By default set to `false` (recommended for production builds). Useful for development when you need to eliminate the cache's effect on testing.
|
|
161
|
-
|
|
162
|
-
#### `ASSET_NAMESPACE`
|
|
163
|
-
|
|
164
|
-
type: KV Namespace Binding
|
|
165
|
-
|
|
166
|
-
The binding name to the KV Namespace populated with key/value entries of files for the Worker to serve. By default, Workers Sites uses a [binding to a Workers KV Namespace](https://developers.cloudflare.com/workers/reference/storage/api/#namespaces) named `__STATIC_CONTENT`.
|
|
167
|
-
|
|
168
|
-
It is further assumed that this namespace consists of static assets such as HTML, CSS, JavaScript, or image files, keyed off of a relative path that roughly matches the assumed URL pathname of the incoming request.
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
return getAssetFromKV(event, { ASSET_NAMESPACE: MY_NAMESPACE })
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
#### `ASSET_MANIFEST` (optional)
|
|
175
|
-
|
|
176
|
-
type: text blob (JSON formatted)
|
|
177
|
-
|
|
178
|
-
The mapping of requested file path to the key stored on Cloudflare.
|
|
179
|
-
|
|
180
|
-
Workers Sites with Wrangler bundles up a text blob that maps request paths to content-hashed keys that are generated by Wrangler as a cache-busting measure. If this option/binding is not present, the function will fallback to using the raw pathname to look up your asset in KV. If, for whatever reason, you have rolled your own implementation of this, you can include your own by passing a stringified JSON object where the keys are expected paths, and the values are the expected keys in your KV namespace.
|
|
181
|
-
|
|
182
|
-
```
|
|
183
|
-
let assetManifest = { "index.html": "index.special.html" }
|
|
184
|
-
return getAssetFromKV(event, { ASSET_MANIFEST: JSON.stringify(assetManifest) })
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
#### `defaultMimeType` (optional)
|
|
188
|
-
|
|
189
|
-
type: string
|
|
190
|
-
|
|
191
|
-
This is the mime type that will be used for files with unrecognized or missing extensions. The default value is `'text/plain'`.
|
|
192
|
-
|
|
193
|
-
If you are serving a static site and would like to use extensionless HTML files instead of index.html files, set this to `'text/html'`.
|
|
194
|
-
|
|
195
|
-
#### `defaultDocument` (optional)
|
|
196
|
-
|
|
197
|
-
type: string
|
|
198
|
-
|
|
199
|
-
This is the default document that will be concatenated for requests ends in `'/'` or without a valid mime type like `'/about'` or `'/about.me'`. The default value is `'index.html'`.
|
|
200
|
-
|
|
201
|
-
# Helper functions
|
|
202
|
-
|
|
203
|
-
## `mapRequestToAsset`
|
|
204
|
-
|
|
205
|
-
mapRequestToAsset(Request) => Request
|
|
206
|
-
|
|
207
|
-
The default function for mapping incoming requests to keys in Cloudflare's KV.
|
|
208
|
-
|
|
209
|
-
Takes any path that ends in `/` or evaluates to an HTML file and appends `index.html` or `/index.html` for lookup in your Workers KV namespace.
|
|
210
|
-
|
|
211
|
-
## `serveSinglePageApp`
|
|
212
|
-
|
|
213
|
-
serveSinglePageApp(Request) => Request
|
|
214
|
-
|
|
215
|
-
A custom handler for mapping requests to a single root: `index.html`. The most common use case is single-page applications - frameworks with in-app routing - such as React Router, VueJS, etc. It takes zero arguments.
|
|
216
|
-
|
|
217
|
-
```js
|
|
218
|
-
import { getAssetFromKV, serveSinglePageApp } from '@cloudflare/kv-asset-handler'
|
|
219
|
-
...
|
|
220
|
-
let asset = await getAssetFromKV(event, { mapRequestToAsset: serveSinglePageApp })
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
# Cache revalidation and etags
|
|
224
|
-
|
|
225
|
-
All responses served from cache (including those with `cf-cache-status: MISS`) include an `etag` response header that identifies the version of the resource. The `etag` value is identical to the path key used in the `ASSET_MANIFEST`. It is updated each time an asset changes and looks like this: `etag: <filename>.<hash of file contents>.<extension>` (ex. `etag: index.54321.html`).
|
|
226
|
-
|
|
227
|
-
Resources served with an `etag` allow browsers to use the `if-none-match` request header to make conditional requests for that resource in the future. This has two major benefits:
|
|
228
|
-
|
|
229
|
-
- When a request's `if-none-match` value matches the `etag` of the resource in Cloudflare cache, Cloudflare will send a `304 Not Modified` response without a body, saving bandwidth.
|
|
230
|
-
- Changes to a file on the server are immediately reflected in the browser - even when the cache control directive `max-age` is unexpired.
|
|
231
|
-
|
|
232
|
-
#### Disable the `etag`
|
|
233
|
-
|
|
234
|
-
To turn `etags` **off**, you must bypass cache:
|
|
235
|
-
|
|
236
|
-
```js
|
|
237
|
-
/* Turn etags off */
|
|
238
|
-
let cacheControl = {
|
|
239
|
-
bypassCache: true,
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### Syntax and comparison context
|
|
244
|
-
|
|
245
|
-
`kv-asset-handler` sets and evaluates etags as [strong validators](https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests#Strong_validation). To preserve `etag` integrity, the format of the value deviates from the [RFC2616 recommendation to enclose the `etag` with quotation marks](https://tools.ietf.org/html/rfc2616#section-3.11). This is intentional. Cloudflare cache applies the `W/` prefix to all `etags` that use quoted-strings -- a process that converts the `etag` to a "weak validator" when served to a client.
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Options, CacheControl, MethodNotAllowedError, NotFoundError, InternalError } from './types';
|
|
2
|
-
declare global {
|
|
3
|
-
var __STATIC_CONTENT: any, __STATIC_CONTENT_MANIFEST: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* maps the path of incoming request to the request pathKey to look up
|
|
7
|
-
* in bucket and in cache
|
|
8
|
-
* e.g. for a path '/' returns '/index.html' which serves
|
|
9
|
-
* the content of bucket/index.html
|
|
10
|
-
* @param {Request} request incoming request
|
|
11
|
-
*/
|
|
12
|
-
declare const mapRequestToAsset: (request: Request, options?: Partial<Options>) => Request;
|
|
13
|
-
/**
|
|
14
|
-
* maps the path of incoming request to /index.html if it evaluates to
|
|
15
|
-
* any HTML file.
|
|
16
|
-
* @param {Request} request incoming request
|
|
17
|
-
*/
|
|
18
|
-
declare function serveSinglePageApp(request: Request, options?: Partial<Options>): Request;
|
|
19
|
-
/**
|
|
20
|
-
* takes the path of the incoming request, gathers the appropriate content from KV, and returns
|
|
21
|
-
* the response
|
|
22
|
-
*
|
|
23
|
-
* @param {FetchEvent} event the fetch event of the triggered request
|
|
24
|
-
* @param {{mapRequestToAsset: (string: Request) => Request, cacheControl: {bypassCache:boolean, edgeTTL: number, browserTTL:number}, ASSET_NAMESPACE: any, ASSET_MANIFEST:any}} [options] configurable options
|
|
25
|
-
* @param {CacheControl} [options.cacheControl] determine how to cache on Cloudflare and the browser
|
|
26
|
-
* @param {typeof(options.mapRequestToAsset)} [options.mapRequestToAsset] maps the path of incoming request to the request pathKey to look up
|
|
27
|
-
* @param {Object | string} [options.ASSET_NAMESPACE] the binding to the namespace that script references
|
|
28
|
-
* @param {any} [options.ASSET_MANIFEST] the map of the key to cache and store in KV
|
|
29
|
-
* */
|
|
30
|
-
declare const getAssetFromKV: (event: FetchEvent, options?: Partial<Options>) => Promise<Response>;
|
|
31
|
-
export { getAssetFromKV, mapRequestToAsset, serveSinglePageApp };
|
|
32
|
-
export { Options, CacheControl, MethodNotAllowedError, NotFoundError, InternalError };
|