sveltekit-python-vercel 0.1.0 → 0.2.0
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 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
|
+
<p align="middle">
|
|
1
2
|
<img width="100" alt="image" src="https://user-images.githubusercontent.com/20548516/218344678-d41f4c4a-6b1b-48cc-8553-2b9fbe2169d6.png"/>
|
|
2
3
|
<img width="100" alt="image" src="https://camo.githubusercontent.com/f1ac9955f30176e6183aeeeac1b77354c7a132696fdc77c06ef0f0bec30f258c/68747470733a2f2f6861636b616461792e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031392f30392f707974686f6e2d6c6f676f2e706e67"/>
|
|
3
4
|
<img width="100" alt="image" src="https://camo.githubusercontent.com/add2c9721e333f0043ac938f3dadbc26a282776e01b95b308fcaba5afaf74ae3/68747470733a2f2f6173736574732e76657263656c2e636f6d2f696d6167652f75706c6f61642f76313538383830353835382f7265706f7369746f726965732f76657263656c2f6c6f676f2e706e67"/>
|
|
5
|
+
</p>
|
|
4
6
|
|
|
5
7
|
# sveltekit-python-vercel
|
|
6
8
|
|
|
7
9
|
Write Python endpoints in [SvelteKit](https://kit.svelte.dev/) and seamlessly deploy them to Vercel.
|
|
8
10
|
|
|
11
|
+
- [Current Features](#current-features)
|
|
12
|
+
- [Installing](#installing)
|
|
13
|
+
- [Testing Locally](#testing-locally)
|
|
14
|
+
- [Deploying to Vercel](#deploying-to-vercel)
|
|
15
|
+
- [Example](#example)
|
|
16
|
+
- [Backend Caveats](#backend-caveats)
|
|
17
|
+
- [Fork of `sveltekit-modal`](#fork-of-sveltekit-modal)
|
|
18
|
+
- [Possible future plans](#possible-future-plans)
|
|
19
|
+
|
|
20
|
+
|
|
9
21
|
**This is very much in beta.**
|
|
10
22
|
|
|
11
23
|
## Current Features
|
|
12
24
|
|
|
13
25
|
- Write `+server.py` files nearly the same way you would write `+server.js` files
|
|
14
|
-
-
|
|
26
|
+
- Deploy (quadi) automatically to Vercel Serverless
|
|
15
27
|
|
|
16
28
|
## Installing
|
|
17
29
|
|
|
18
30
|
- Open or set up your SvelteKit project
|
|
19
|
-
- Install
|
|
31
|
+
- Install SvelteKit's Vercel adapter: `pnpm i -D @sveltejs/adapter-vercel`
|
|
32
|
+
- Install with `pnpm i -D sveltekit-python-vercel`
|
|
20
33
|
- Update your `vite.config.js`
|
|
21
34
|
|
|
22
35
|
```javascript
|
|
@@ -34,7 +47,7 @@ Write Python endpoints in [SvelteKit](https://kit.svelte.dev/) and seamlessly de
|
|
|
34
47
|
- Update your `svelte.config.js`:
|
|
35
48
|
|
|
36
49
|
```javascript
|
|
37
|
-
import adapter from "@sveltejs/adapter-vercel";
|
|
50
|
+
import adapter from "@sveltejs/adapter-vercel"; // Use the vercel adapter
|
|
38
51
|
import { vitePreprocess } from "@sveltejs/kit/vite";
|
|
39
52
|
|
|
40
53
|
/** @type {import('@sveltejs/kit').Config} */
|
|
@@ -97,7 +110,30 @@ Using [Poetry](https://python-poetry.org/) to manage your virtual environments w
|
|
|
97
110
|
- Required packages are python3.9 (that is what Vercel's runtime uses), `fastapi`, and `uvicorn`.
|
|
98
111
|
- Install whatever other dependencies you need from pypi using `poetry add package-name`
|
|
99
112
|
|
|
113
|
+
- Enter your virtual env with `poetry shell`
|
|
100
114
|
- Run `pnpm dev` or `npm dev`
|
|
115
|
+
- You should see both the usual SvelteKit server start as well as the unvicorn server (by default on `http://0.0.0.0:8000`) in the console.
|
|
116
|
+
|
|
117
|
+
## Deploying to Vercel
|
|
118
|
+
- At the moment this requires a tiny bit of extra labor besides just pushing to your repository. I believe this is because of the way Vercel looks for serverless functions, but I hope to make this a bit easier in the future.
|
|
119
|
+
|
|
120
|
+
- When you make changes to your python endpoints, you have to manually regenerate the `/api` folder by running:
|
|
121
|
+
1. `poetry export -f requirements.txt --output requirements.txt --without-hashes`
|
|
122
|
+
2. `node ./node_modules/sveltekit-python-vercel/esm/src/vite/sveltekit_python_vercel/bin.mjs`
|
|
123
|
+
- Then commit `requirements.txt` and the changes in `/api` and push.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
Note:
|
|
127
|
+
- To make this a bit smoother, you can add a script to you `package.json`:
|
|
128
|
+
```json
|
|
129
|
+
"scripts": {
|
|
130
|
+
...
|
|
131
|
+
"py-update": "poetry export -f requirements.txt --output requirements.txt --without-hashes; node ./node_modules/sveltekit-python-vercel/esm/src/vite/sveltekit_python_vercel/bin.mjs"
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
- and then just run `pnpm py-update`
|
|
135
|
+
|
|
136
|
+
|
|
101
137
|
|
|
102
138
|
|
|
103
139
|
## Example
|
|
@@ -174,9 +210,13 @@ Using [Poetry](https://python-poetry.org/) to manage your virtual environments w
|
|
|
174
210
|
|
|
175
211
|
```
|
|
176
212
|
|
|
177
|
-
|
|
213
|
+
### Backend Caveats
|
|
178
214
|
|
|
179
215
|
There are currently a few things that have to be worked around.
|
|
216
|
+
- `GET` endpoints are directly fed the parameters from the url, so when you define an endpoint
|
|
217
|
+
- All other endpoints are fed the body as a JSON. The recommended way to deal with this is to use a pydantic model and pass it as the singular input to the function.
|
|
218
|
+
|
|
219
|
+
See the example above.
|
|
180
220
|
|
|
181
221
|
## Fork of `sveltekit-modal`
|
|
182
222
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"module": "./esm/mod.js",
|
|
3
3
|
"types": "./types/mod.d.ts",
|
|
4
4
|
"name": "sveltekit-python-vercel",
|
|
5
|
-
"version": "v0.
|
|
5
|
+
"version": "v0.2.0",
|
|
6
6
|
"description": "Write Sveltekit server endpoints in Python and seamlessly deploy to Vercel",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|