@openworkers/adapter-sveltekit 0.4.2 → 0.4.5
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/README.md +44 -6
- package/dist/function-worker.js +16 -0
- package/dist/worker.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,8 +17,8 @@ import adapter from '@openworkers/adapter-sveltekit';
|
|
|
17
17
|
export default {
|
|
18
18
|
kit: {
|
|
19
19
|
adapter: adapter({
|
|
20
|
-
out: 'dist',
|
|
21
|
-
functions: false
|
|
20
|
+
out: 'dist', // Output directory (default: 'dist')
|
|
21
|
+
functions: false // Generate mini-workers for API routes (default: false)
|
|
22
22
|
})
|
|
23
23
|
}
|
|
24
24
|
};
|
|
@@ -26,10 +26,10 @@ export default {
|
|
|
26
26
|
|
|
27
27
|
## Options
|
|
28
28
|
|
|
29
|
-
| Option
|
|
30
|
-
|
|
31
|
-
| `out`
|
|
32
|
-
| `functions` | `boolean` | `false`
|
|
29
|
+
| Option | Type | Default | Description |
|
|
30
|
+
| ----------- | --------- | -------- | ------------------------------------------------- |
|
|
31
|
+
| `out` | `string` | `'dist'` | Output directory for the build |
|
|
32
|
+
| `functions` | `boolean` | `false` | Generate separate mini-workers for each API route |
|
|
33
33
|
|
|
34
34
|
## Output
|
|
35
35
|
|
|
@@ -90,6 +90,44 @@ declare global {
|
|
|
90
90
|
export {};
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
## Deployment
|
|
94
|
+
|
|
95
|
+
Build your SvelteKit app, then deploy it with the [OpenWorkers CLI](https://github.com/openworkers/openworkers-cli):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Build
|
|
99
|
+
bun run build
|
|
100
|
+
|
|
101
|
+
# Deploy
|
|
102
|
+
ow workers upload my-app ./dist
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
For a first deployment, you'll need to set up the worker and its assets binding:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Create the worker
|
|
109
|
+
ow workers create my-app -d "My SvelteKit App"
|
|
110
|
+
|
|
111
|
+
# Create a storage bucket for static assets
|
|
112
|
+
ow storage create my-storage
|
|
113
|
+
|
|
114
|
+
# Create an environment and bind the storage as ASSETS
|
|
115
|
+
ow env create my-app-env
|
|
116
|
+
ow env bind my-app-env ASSETS my-storage --type assets
|
|
117
|
+
|
|
118
|
+
# Link the environment to the worker
|
|
119
|
+
ow workers link my-app my-app-env
|
|
120
|
+
# Build and upload
|
|
121
|
+
bun run build
|
|
122
|
+
ow workers upload my-app ./dist
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
- [world-time-app](https://github.com/max-lt/world-time-app) — SSR-rendered clocks with server-side positioned hands
|
|
128
|
+
- [httpbin](https://github.com/max-lt/httpbin) — HTTP request testing tool
|
|
129
|
+
- [rock-paper-scissors](https://github.com/max-lt/rock-paper-scissors) — Provably fair Rock Paper Scissors game
|
|
130
|
+
|
|
93
131
|
## License
|
|
94
132
|
|
|
95
133
|
MIT
|
package/dist/function-worker.js
CHANGED
|
@@ -3,6 +3,10 @@ import * as handlers from "ENDPOINT";
|
|
|
3
3
|
var worker = {
|
|
4
4
|
async fetch(req, env, ctx) {
|
|
5
5
|
globalThis.env = env;
|
|
6
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
7
|
+
if (proto && !req.url.startsWith(proto)) {
|
|
8
|
+
req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
|
|
9
|
+
}
|
|
6
10
|
const method = req.method;
|
|
7
11
|
const handler = handlers[method];
|
|
8
12
|
if (!handler) {
|
|
@@ -52,6 +56,18 @@ var worker = {
|
|
|
52
56
|
}
|
|
53
57
|
return response;
|
|
54
58
|
} catch (error) {
|
|
59
|
+
if (error?.status >= 300 && error?.status < 400 && error?.location) {
|
|
60
|
+
return new Response(null, {
|
|
61
|
+
status: error.status,
|
|
62
|
+
headers: { Location: error.location }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (error?.status && error?.body) {
|
|
66
|
+
return new Response(JSON.stringify(error.body), {
|
|
67
|
+
status: error.status,
|
|
68
|
+
headers: { "Content-Type": "application/json" }
|
|
69
|
+
});
|
|
70
|
+
}
|
|
55
71
|
console.error(`[Function] Error in ${method} handler:`, error);
|
|
56
72
|
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
57
73
|
status: 500,
|
package/dist/worker.js
CHANGED
|
@@ -31,6 +31,10 @@ var initialized = server.init({
|
|
|
31
31
|
var worker = {
|
|
32
32
|
async fetch(req, env, ctx) {
|
|
33
33
|
globalThis.env = env;
|
|
34
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
35
|
+
if (proto && !req.url.startsWith(proto)) {
|
|
36
|
+
req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
|
|
37
|
+
}
|
|
34
38
|
if (!origin) {
|
|
35
39
|
origin = new URL(req.url).origin;
|
|
36
40
|
}
|