mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
public commit
This commit is contained in:
172
examples/cloudflare-worker/.gitignore
vendored
Normal file
172
examples/cloudflare-worker/.gitignore
vendored
Normal 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/
|
||||
24
examples/cloudflare-worker/build.ts
Normal file
24
examples/cloudflare-worker/build.ts
Normal 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);
|
||||
20
examples/cloudflare-worker/package.json
Normal file
20
examples/cloudflare-worker/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
22
examples/cloudflare-worker/src/index.ts
Normal file
22
examples/cloudflare-worker/src/index.ts
Normal 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
|
||||
);
|
||||
22
examples/cloudflare-worker/tsconfig.json
Normal file
22
examples/cloudflare-worker/tsconfig.json
Normal 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"]
|
||||
}
|
||||
12
examples/cloudflare-worker/worker-configuration.d.ts
vendored
Normal file
12
examples/cloudflare-worker/worker-configuration.d.ts
vendored
Normal 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;
|
||||
}
|
||||
13
examples/cloudflare-worker/wrangler.toml
Normal file
13
examples/cloudflare-worker/wrangler.toml
Normal 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"
|
||||
Reference in New Issue
Block a user