feat: local debugging with wrangler

Signed-off-by: Tom Plant <tom@tplant.com.au>
pull/5/head
Tom Plant 2024-01-14 08:12:02 +00:00
parent 1e183247cf
commit 3b20472433
No known key found for this signature in database
8 changed files with 6165 additions and 101 deletions

2
.gitignore vendored
View File

@ -36,3 +36,5 @@ next-env.d.ts
.terraform/ .terraform/
terraform.tfstate* terraform.tfstate*
/.wrangler

9
env.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
UPTIMEFLARE_STATE: KVNamespace;
}
}
}
export {};

View File

@ -4,3 +4,15 @@ const nextConfig = {
} }
module.exports = nextConfig module.exports = nextConfig
if (process.env.NODE_ENV === 'development') {
const { setupDevBindings } = require('@cloudflare/next-on-pages/next-dev')
setupDevBindings({
bindings: {
UPTIMEFLARE_STATE: {
type: 'kv',
id: 'UPTIMEFLARE_STATE'
}
}
})
}

6232
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",
"preview": "npx @cloudflare/next-on-pages && wrangler pages dev .vercel/output/static --compatibility-flag nodejs_compat --kv UPTIMEFLARE_STATE",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint" "lint": "next lint"
@ -25,6 +26,7 @@
"react-dom": "^18" "react-dom": "^18"
}, },
"devDependencies": { "devDependencies": {
"@cloudflare/next-on-pages": "^1.8.5",
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^18", "@types/react": "^18",
"@types/react-dom": "^18", "@types/react-dom": "^18",

View File

@ -15,7 +15,8 @@
"incremental": true, "incremental": true,
"paths": { "paths": {
"@/*": ["./*"] "@/*": ["./*"]
} },
"types": ["@cloudflare/workers-types"]
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "worker/**/*.ts"] "exclude": ["node_modules", "worker/**/*.ts"]

View File

@ -5,7 +5,7 @@
"scripts": { "scripts": {
"vercel-build": "next build", "vercel-build": "next build",
"deploy": "wrangler deploy", "deploy": "wrangler deploy",
"dev": "wrangler dev", "dev": "wrangler dev --config wrangler-dev.toml --test-scheduled --persist-to ../.wrangler/state",
"start": "wrangler dev" "start": "wrangler dev"
}, },
"devDependencies": { "devDependencies": {

4
worker/wrangler-dev.toml Normal file
View File

@ -0,0 +1,4 @@
name = "uptimeflare_worker"
main = "src/index.ts"
compatibility_date = "2023-11-08"
kv_namespaces = [{ binding = "UPTIMEFLARE_STATE", id = "UPTIMEFLARE_STATE" }]