initial commit
This commit is contained in:
commit
9137907d8d
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
|
/build
|
||||||
|
/.svelte-kit
|
||||||
|
/package
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
vite.config.js.timestamp-*
|
||||||
|
vite.config.ts.timestamp-*
|
4
.prettierignore
Normal file
4
.prettierignore
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Ignore files for PNPM, NPM and YARN
|
||||||
|
pnpm-lock.yaml
|
||||||
|
package-lock.json
|
||||||
|
yarn.lock
|
8
.prettierrc
Normal file
8
.prettierrc
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"useTabs": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"printWidth": 100,
|
||||||
|
"plugins": ["prettier-plugin-svelte"],
|
||||||
|
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||||
|
}
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# svelte-kit-pg-cloudflare
|
||||||
|
|
||||||
|
An example sveltekit project showing how deploys to cloudflare are seemingly broken when using certain node modules, even though those same modules work when using wrangler's default build process (esbuild) to deploy.
|
||||||
|
|
||||||
|
See [raw-pg-cloudflare](https://terrible.software/terribleplan/raw-pg-cloudflare) for the working esbuild-based deployment.
|
2816
package-lock.json
generated
Normal file
2816
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
29
package.json
Normal file
29
package.json
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "svelte-kit-knex-cloudflare",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite dev",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"lint": "prettier --check .",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"deploy": "wrangler deploy"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sveltejs/adapter-auto": "^3.0.0",
|
||||||
|
"@sveltejs/adapter-cloudflare-workers": "^2.1.0",
|
||||||
|
"@sveltejs/kit": "^2.0.0",
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||||
|
"knex": "^3.1.0",
|
||||||
|
"kysely": "^0.27.2",
|
||||||
|
"pg": "^8.11.3",
|
||||||
|
"pg-cursor": "^2.10.3",
|
||||||
|
"prettier": "^3.1.1",
|
||||||
|
"prettier-plugin-svelte": "^3.1.2",
|
||||||
|
"svelte": "^4.2.7",
|
||||||
|
"vite": "^5.0.3",
|
||||||
|
"wrangler": "^3.30.1"
|
||||||
|
},
|
||||||
|
"type": "module"
|
||||||
|
}
|
12
src/app.html
Normal file
12
src/app.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
%sveltekit.head%
|
||||||
|
</head>
|
||||||
|
<body data-sveltekit-preload-data="hover">
|
||||||
|
<div style="display: contents">%sveltekit.body%</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
src/lib/index.js
Normal file
1
src/lib/index.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// place files you want to import through the `$lib` alias in this folder.
|
20
src/routes/+page.server.js
Normal file
20
src/routes/+page.server.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { Kysely, PostgresDialect } from 'kysely';
|
||||||
|
import pg from 'pg';
|
||||||
|
const { Pool } = pg;
|
||||||
|
import Cursor from 'pg-cursor';
|
||||||
|
|
||||||
|
export const load = async ({ request, locals: { app, user, sb }, cookies, platform: { DB } }) => {
|
||||||
|
console.log(JSON.stringify(DB));
|
||||||
|
const db = new Kysely({
|
||||||
|
dialect: new PostgresDialect({ pool: new Pool(DB) }),
|
||||||
|
cursor: Cursor,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
users: await db.selectFrom('users').select(['id']).execute(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
6
src/routes/+page.svelte
Normal file
6
src/routes/+page.svelte
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<script>
|
||||||
|
export let data;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>USERS:</h1>
|
||||||
|
<pre>{JSON.stringify(users, null, 2)}</pre>
|
BIN
static/favicon.png
Normal file
BIN
static/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
7
svelte.config.js
Normal file
7
svelte.config.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import adapter from '@sveltejs/adapter-cloudflare-workers';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
kit: {
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
};
|
6
vite.config.js
Normal file
6
vite.config.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [sveltekit()]
|
||||||
|
});
|
22
wrangler.toml
Normal file
22
wrangler.toml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
name = "svelte-kit-knex-cloudflare"
|
||||||
|
main = "./.cloudflare/worker.js"
|
||||||
|
site.bucket = "./.cloudflare/public"
|
||||||
|
compatibility_date = "2024-03-02"
|
||||||
|
|
||||||
|
# compatibility_flags = [ "nodejs_compat" ]
|
||||||
|
# ^ fails with errors like
|
||||||
|
# Cannot use "fs" when deploying to Cloudflare.
|
||||||
|
|
||||||
|
node_compat = true
|
||||||
|
# ^ this doesn't work either
|
||||||
|
# which is strange because it _does_ work when not using svelte(kit)
|
||||||
|
# fails with similar same errors as above, but also more...
|
||||||
|
# such as
|
||||||
|
# Cannot use "node:string_decoder" when deploying to Cloudflare.
|
||||||
|
#
|
||||||
|
# so it's even _more_ broken because the node: prefix is _also_ broken somehow
|
||||||
|
build.command = "npm run build"
|
||||||
|
|
||||||
|
[[hyperdrive]]
|
||||||
|
binding = "DB"
|
||||||
|
id = "<redacted>"
|
Loading…
Reference in a new issue