diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e9ede723..5d5c5a2c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -253,6 +253,9 @@ importers: templates/default: dependencies: + '@hono/node-server': + specifier: latest + version: 1.8.2 frog: specifier: latest version: link:../../src @@ -1817,13 +1820,18 @@ packages: resolution: {integrity: sha512-9ondWs/5EuyZOd/iyiRp0GQfMEq+IA+IbV8Wy2bgdr5+cC55I3xbQrqtXKprw7jJhfvq3IVw7ALiuvCEmLdCAA==} engines: {node: '>=18.14.1'} + /@hono/node-server@1.8.2: + resolution: {integrity: sha512-h8l2TBLCPHZBUrrkosZ6L5CpBLj6zdESyF4B+zngiCDF7aZFQJ0alVbLx7jn8PCVi9EyoFf8a4hOZFi1tD95EA==} + engines: {node: '>=18.14.1'} + dev: false + /@hono/vite-dev-server@0.7.0(hono@4.0.4): resolution: {integrity: sha512-NFcBuyklOammhiExJUYvTfzoU9Mzv4F7ddUCjTe9hy37/AHGZXoksZaBWFl2fRSPVZaPvmX9eiRLBMIrML2iYw==} engines: {node: '>=18.14.1'} peerDependencies: hono: '*' dependencies: - '@hono/node-server': 1.8.1 + '@hono/node-server': 1.8.2 hono: 4.0.4 miniflare: 3.20240129.3 minimatch: 9.0.3 diff --git a/src/cli/commands/dev.ts b/src/cli/commands/dev.ts index e8b4227c..a46d822e 100644 --- a/src/cli/commands/dev.ts +++ b/src/cli/commands/dev.ts @@ -12,13 +12,14 @@ type DevOptions = { host?: boolean port?: number proxy?: 'cloudflared' | 'ngrok' + staticPath?: string } export async function dev( entry_: string | undefined, options: DevOptions = {}, ) { - const { host, port, proxy } = options + const { host, port, proxy, staticPath } = options const entry = entry_ || (await findEntrypoint()) const entry_resolved = resolve(join(process.cwd(), entry)) @@ -31,8 +32,12 @@ export async function dev( host, port, }, + publicDir: staticPath ?? 'public', plugins: [ devServer({ + exclude: [ + /.+\.(gif|jpe?g|tiff?|png|webp|bmp|woff|eot|woff2|ttf|otf|ico|txt)$/, + ], entry: entry_resolved, // Note: we are not relying on the default export so we can be compatible with // runtimes that rely on it (ie. Vercel Serverless Functions). diff --git a/src/cli/index.ts b/src/cli/index.ts index af64e57f..97dbca23 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -19,6 +19,7 @@ cli '-P, --proxy [string]', 'Start proxy for dev server (experimental). Valid options are `cloudflared` and `ngrok`.', ) + .option('-s, --staticPath [string]', 'Path to static files (default: public)') .example((name) => `${name} dev --host`) .example((name) => `${name} dev --port 6969`) .example((name) => `${name} dev --proxy ngrok`) diff --git a/templates/bun/public/icon.png b/templates/bun/public/icon.png new file mode 100644 index 00000000..76b454b1 Binary files /dev/null and b/templates/bun/public/icon.png differ diff --git a/templates/bun/src/index.tsx b/templates/bun/src/index.tsx index 97dbab25..122afde5 100644 --- a/templates/bun/src/index.tsx +++ b/templates/bun/src/index.tsx @@ -1,4 +1,3 @@ -import { serve } from 'bun' import { Button, Frog, TextInput } from 'frog' export const app = new Frog({ @@ -56,8 +55,11 @@ app.frame('/', (c) => { }) }) -serve({ - fetch: app.fetch, - port: 3000, -}) -console.log('Server is running on port 3000') +if (typeof Bun !== 'undefined') { + app.use('/*', (await import('hono/bun')).serveStatic({ root: './public' })) + Bun.serve({ + fetch: app.fetch, + port: 3000, + }) + console.log('Server is running on port 3000') +} diff --git a/templates/bun/tsconfig.json b/templates/bun/tsconfig.json index c442b33f..32f3a20f 100644 --- a/templates/bun/tsconfig.json +++ b/templates/bun/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "module": "NodeNext", "strict": true, "jsx": "react-jsx", "jsxImportSource": "hono/jsx" diff --git a/templates/cloudflare-worker/public/icon.png b/templates/cloudflare-worker/public/icon.png new file mode 100644 index 00000000..76b454b1 Binary files /dev/null and b/templates/cloudflare-worker/public/icon.png differ diff --git a/templates/cloudflare-worker/src/index.tsx b/templates/cloudflare-worker/src/index.tsx index 11c2983d..341a205f 100644 --- a/templates/cloudflare-worker/src/index.tsx +++ b/templates/cloudflare-worker/src/index.tsx @@ -1,4 +1,5 @@ import { Button, Frog, TextInput } from 'frog' +import { serveStatic } from 'hono/cloudflare-workers' export const app = new Frog({ // Supply a Hub API URL to enable frame verification. @@ -55,4 +56,13 @@ app.frame('/', (c) => { }) }) +if (import.meta.env?.MODE !== 'development') + app.use( + '/*', + serveStatic({ + root: './', + manifest: await import('__STATIC_CONTENT_MANIFEST'), + }), + ) + export default app diff --git a/templates/cloudflare-worker/wrangler.toml b/templates/cloudflare-worker/wrangler.toml index acf16443..4af6f2fd 100644 --- a/templates/cloudflare-worker/wrangler.toml +++ b/templates/cloudflare-worker/wrangler.toml @@ -1,6 +1,9 @@ name = "frog-template" compatibility_date = "2023-12-01" +[site] +bucket = "./public" + # [vars] # MY_VARIABLE = "production_value" diff --git a/templates/default/package.json b/templates/default/package.json index 91f0f96c..b1647c14 100644 --- a/templates/default/package.json +++ b/templates/default/package.json @@ -6,6 +6,7 @@ "dev": "frog dev" }, "dependencies": { + "@hono/node-server": "latest", "frog": "latest", "hono": "^4" }, diff --git a/templates/default/public/icon.png b/templates/default/public/icon.png new file mode 100644 index 00000000..76b454b1 Binary files /dev/null and b/templates/default/public/icon.png differ diff --git a/templates/default/src/index.tsx b/templates/default/src/index.tsx index 33321273..48b74a5a 100644 --- a/templates/default/src/index.tsx +++ b/templates/default/src/index.tsx @@ -1,3 +1,4 @@ +import { serveStatic } from '@hono/node-server/serve-static' import { Button, Frog, TextInput } from 'frog' export const app = new Frog({ @@ -5,6 +6,8 @@ export const app = new Frog({ // hubApiUrl: 'https://api.hub.wevm.dev', }) +app.use('/*', serveStatic({ root: './public' })) + app.frame('/', (c) => { const { buttonValue, inputText, status } = c const fruit = inputText || buttonValue diff --git a/templates/next/app/api/[[...routes]]/route.tsx b/templates/next/app/api/[[...routes]]/route.tsx index a4191b7f..ed5e15aa 100644 --- a/templates/next/app/api/[[...routes]]/route.tsx +++ b/templates/next/app/api/[[...routes]]/route.tsx @@ -4,6 +4,7 @@ import { Button, Frog, TextInput } from 'frog' import { handle } from 'frog/next' const app = new Frog({ + assetsPath: '/', basePath: '/api', // Supply a Hub API URL to enable frame verification. // hubApiUrl: 'https://api.hub.wevm.dev', diff --git a/templates/node/public/icon.png b/templates/node/public/icon.png new file mode 100644 index 00000000..76b454b1 Binary files /dev/null and b/templates/node/public/icon.png differ diff --git a/templates/node/src/index.tsx b/templates/node/src/index.tsx index 4cd9a329..5b86bf11 100644 --- a/templates/node/src/index.tsx +++ b/templates/node/src/index.tsx @@ -1,4 +1,5 @@ import { serve } from '@hono/node-server' +import { serveStatic } from '@hono/node-server/serve-static' import { Button, Frog, TextInput } from 'frog' export const app = new Frog({ @@ -6,6 +7,8 @@ export const app = new Frog({ // hubApiUrl: 'https://api.hub.wevm.dev', }) +app.use('/*', serveStatic({ root: './public' })) + app.frame('/', (c) => { const { buttonValue, inputText, status } = c const fruit = inputText || buttonValue diff --git a/templates/vercel/api/index.tsx b/templates/vercel/api/index.tsx index 6899e3f5..ee469d6a 100644 --- a/templates/vercel/api/index.tsx +++ b/templates/vercel/api/index.tsx @@ -7,6 +7,7 @@ import { handle } from 'frog/vercel' // } export const app = new Frog({ + assetsPath: '/', basePath: '/api', // Supply a Hub API URL to enable frame verification. // hubApiUrl: 'https://api.hub.wevm.dev', diff --git a/templates/vercel/public/icon.png b/templates/vercel/public/icon.png new file mode 100644 index 00000000..76b454b1 Binary files /dev/null and b/templates/vercel/public/icon.png differ diff --git a/tsconfig.json b/tsconfig.json index 064b1a43..0da2469b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { // This configuration is used for local development and type checking. "extends": "./tsconfig.base.json", - "exclude": ["templates/next", "create-frog/templates"], + "exclude": ["templates/*", "create-frog/templates"], "include": ["create-frog", "examples", "templates", "src"], "compilerOptions": { "jsx": "react-jsx",