mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-09 23:21:30 -07:00
Initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# {{ slug name }}
|
||||
|
||||
A Cloudflare Workers application using Hono and Vite
|
||||
|
||||
## Development
|
||||
|
||||
### Run in dev mode
|
||||
|
||||
```sh
|
||||
pnpm turbo dev
|
||||
```
|
||||
|
||||
### Run in preview mode
|
||||
|
||||
```sh
|
||||
pnpm turbo preview
|
||||
```
|
||||
|
||||
### Run tests
|
||||
|
||||
```sh
|
||||
pnpm test
|
||||
```
|
||||
|
||||
### Deploy
|
||||
|
||||
```sh
|
||||
pnpm turbo deploy
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
// oxlint-disable @typescript-eslint/consistent-type-imports
|
||||
type LocalEnv = import('./src/context').Env
|
||||
type MainModule = typeof import('./src/{{ slug name }}.app')
|
||||
|
||||
// Add Env to Cloudflare namespace so that we can access it via
|
||||
// import { env } from 'cloudflare:workers'
|
||||
declare namespace Cloudflare {
|
||||
interface Env extends LocalEnv {}
|
||||
interface GlobalProps {
|
||||
mainModule: MainModule
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "{{ slug name }}",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "run-vite-build",
|
||||
"check:lint": "run-oxlint",
|
||||
"check:types": "run-tsc",
|
||||
"check:workers-types": "run-wrangler-types --check",
|
||||
"deploy": "run-wrangler-deploy",
|
||||
"dev": "run-vite-dev",
|
||||
"fix:workers-types": "run-wrangler-types",
|
||||
"preview": "run-vite-preview",
|
||||
"test": "run-vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@repo/hono-helpers": "workspace:*",
|
||||
"hono": "4.7.8",
|
||||
"workers-tagged-logger": "0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/vite-plugin": "^1.1.0",
|
||||
"@cloudflare/vitest-pool-workers": "0.8.24",
|
||||
"@repo/tools": "workspace:*",
|
||||
"@repo/typescript-config": "workspace:*",
|
||||
"@types/node": "22.15.3",
|
||||
"vite": "^6.3.4",
|
||||
"vitest": "3.1.2",
|
||||
"wrangler": "4.14.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { HonoApp } from '@repo/hono-helpers'
|
||||
import type { SharedHonoEnv, SharedHonoVariables } from '@repo/hono-helpers/src/types'
|
||||
|
||||
export type Env = SharedHonoEnv & {
|
||||
// add additional Bindings here
|
||||
}
|
||||
|
||||
/** Variables can be extended */
|
||||
export type Variables = SharedHonoVariables
|
||||
|
||||
export interface App extends HonoApp {
|
||||
Bindings: Env
|
||||
Variables: Variables
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { SELF } from 'cloudflare:test'
|
||||
import { expect, it } from 'vitest'
|
||||
|
||||
it('response with hello world', async () => {
|
||||
const res = await SELF.fetch('https://example.com')
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.text()).toMatchInlineSnapshot(`"hello, world!"`)
|
||||
})
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Hono } from 'hono'
|
||||
import { useWorkersLogger } from 'workers-tagged-logger'
|
||||
|
||||
import { withNotFound, withOnError } from '@repo/hono-helpers'
|
||||
|
||||
import type { App } from './context'
|
||||
|
||||
const app = new Hono<App>()
|
||||
.use(
|
||||
'*',
|
||||
// middleware
|
||||
(c, next) =>
|
||||
useWorkersLogger(c.env.NAME, {
|
||||
environment: c.env.ENVIRONMENT,
|
||||
release: c.env.SENTRY_RELEASE,
|
||||
})(c, next)
|
||||
)
|
||||
|
||||
.onError(withOnError())
|
||||
.notFound(withNotFound())
|
||||
|
||||
.get('/', async (c) => {
|
||||
return c.text('hello, world!')
|
||||
})
|
||||
|
||||
export default app
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "@repo/typescript-config/workers.json"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { cloudflare } from '@cloudflare/vite-plugin'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [cloudflare()],
|
||||
})
|
||||
@@ -0,0 +1,15 @@
|
||||
import { cloudflareTest } from '@cloudflare/vitest-pool-workers'
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
cloudflareTest({
|
||||
wrangler: { configPath: `${__dirname}/wrangler.jsonc` },
|
||||
miniflare: {
|
||||
bindings: {
|
||||
ENVIRONMENT: 'VITEST',
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"$schema": "node_modules/wrangler/config-schema.json",
|
||||
"name": "{{ slug name }}",
|
||||
"main": "src/{{ slug name }}.app.ts",
|
||||
"compatibility_date": "2025-09-20",
|
||||
"compatibility_flags": ["nodejs_compat"],
|
||||
"routes": [],
|
||||
"upload_source_maps": true,
|
||||
"observability": {
|
||||
"logs": {
|
||||
"enabled": true,
|
||||
"head_sampling_rate": 1 // 100%
|
||||
}
|
||||
},
|
||||
"vars": {
|
||||
"ENVIRONMENT": "development", // overridden during deployment
|
||||
"SENTRY_RELEASE": "unknown" // overridden during deployment
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user