public commit

This commit is contained in:
dswbx
2024-11-16 12:01:47 +01:00
commit 90f80c4280
582 changed files with 49291 additions and 0 deletions

172
examples/cloudflare-worker/.gitignore vendored Normal file
View File

@@ -0,0 +1,172 @@
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
\*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
\*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
\*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
\*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*
# wrangler project
.dev.vars
.wrangler/

View File

@@ -0,0 +1,24 @@
import { $ } from "bun";
//import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import esbuild from "esbuild";
const result = await esbuild.build({
//plugins: [NodeModulesPolyfillPlugin()],
platform: "browser",
conditions: ["worker", "browser"],
entryPoints: ["./src/index.ts"],
outdir: "dist",
external: [],
format: "esm",
target: "es2022",
keepNames: true,
bundle: true,
metafile: true,
minify: true,
define: {
IS_CLOUDFLARE_WORKER: "true"
}
});
await Bun.write("dist/meta.json", JSON.stringify(result.metafile));
//console.log("result", result.metafile);

View File

@@ -0,0 +1,20 @@
{
"name": "cloudflare-worker",
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"test": "vitest",
"cf-typegen": "wrangler types"
},
"dependencies": {
"bknd": "workspace:*"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241106.0",
"typescript": "^5.5.2",
"wrangler": "^3.86.0"
}
}

View File

@@ -0,0 +1,22 @@
import { serve } from "bknd/adapter/cloudflare";
import manifest from "__STATIC_CONTENT_MANIFEST";
export default serve(
{
app: (env: Env) => ({
connection: {
type: "libsql",
config: {
url: env.DB_URL,
authToken: env.DB_TOKEN
}
}
}),
onBuilt: async (app) => {
app.modules.server.get("/", (c) => c.json({ hello: "world" }));
},
setAdminHtml: true
},
manifest
);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"jsx": "react-jsx",
"module": "es2022",
"moduleResolution": "Bundler",
"types": ["@cloudflare/workers-types/2023-07-01"],
"resolveJsonModule": true,
"allowJs": true,
"checkJs": false,
"noEmit": true,
"isolatedModules": true,
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["test"],
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
}

View File

@@ -0,0 +1,12 @@
// Generated by Wrangler
// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
interface Env {
DB_URL: string;
DB_TOKEN: string;
}
declare module "__STATIC_CONTENT_MANIFEST" {
const value: string;
export default value;
}

View File

@@ -0,0 +1,13 @@
#:schema node_modules/wrangler/config-schema.json
name = "bknd-cf-worker-example"
main = "src/index.ts"
compatibility_date = "2024-11-06"
compatibility_flags = ["nodejs_compat"]
workers_dev = true
minify = true
[observability]
enabled = true
[site]
bucket = "../../app/dist/static"