initial commit

This commit is contained in:
Kegan Myers 2024-03-02 13:16:06 -06:00
commit 9137907d8d
15 changed files with 2947 additions and 0 deletions

10
.gitignore vendored Normal file
View 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-*

1
.npmrc Normal file
View file

@ -0,0 +1 @@
engine-strict=true

4
.prettierignore Normal file
View file

@ -0,0 +1,4 @@
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

8
.prettierrc Normal file
View 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
View 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

File diff suppressed because it is too large Load diff

29
package.json Normal file
View 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
View 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
View file

@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

View 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
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

7
svelte.config.js Normal file
View file

@ -0,0 +1,7 @@
import adapter from '@sveltejs/adapter-cloudflare-workers';
export default {
kit: {
adapter: adapter()
}
};

6
vite.config.js Normal file
View 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
View 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>"