Skip to content

Commit

Permalink
feat: isomorphic serveStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Mar 3, 2024
1 parent 71a8c77 commit a7beefe
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 8 deletions.
10 changes: 9 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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).
Expand Down
1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
7 changes: 7 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"types": "./_lib/next/index.d.ts",
"default": "./_lib/next/index.js"
},
"./serve-static": {
"types": "./_lib/serve-static/index.d.ts",
"bun": "./_lib/serve-static/bun.js",
"worker": "./_lib/serve-static/worker.js",
"default": "./_lib/serve-static/index.js"
},
"./vercel": {
"types": "./_lib/vercel/index.d.ts",
"default": "./_lib/vercel/index.js"
Expand All @@ -56,6 +62,7 @@
"dependencies": {
"@bufbuild/protobuf": "^1.7.2",
"@farcaster/core": "^0.13.7",
"@hono/node-server": "^1.8.2",
"@hono/vite-dev-server": "0.7.0",
"@ngrok/ngrok": "^1.1.0",
"@noble/curves": "^1.3.0",
Expand Down
1 change: 1 addition & 0 deletions src/serve-static/bun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { serveStatic } from 'hono/bun'
1 change: 1 addition & 0 deletions src/serve-static/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { serveStatic } from '@hono/node-server/serve-static'
5 changes: 5 additions & 0 deletions src/serve-static/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "module",
"types": "../_lib/serve-static/index.d.ts",
"module": "../_lib/serve-static/index.js"
}
8 changes: 8 additions & 0 deletions src/serve-static/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { serveStatic as serveStatic_ } from 'hono/cloudflare-workers'

export const serveStatic: typeof serveStatic_ = (parameters) =>
serveStatic_({
...parameters,
// @ts-expect-error
manifest: import('__STATIC_CONTENT_MANIFEST'),
})
Binary file added templates/bun/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions templates/bun/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { serve } from 'bun'
import { Button, Frog, TextInput } from 'frog'
import { serveStatic } from 'frog/serve-static'

export const app = new Frog({
// Supply a Hub API URL to enable frame verification.
// hubApiUrl: 'https://api.hub.wevm.dev',
})

app.use('/*', serveStatic({ root: './public' }))

Check failure on line 9 in templates/bun/src/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / Types

No overload matches this call.

app.frame('/', (c) => {
const { buttonValue, inputText, status } = c
const fruit = inputText || buttonValue
Expand Down Expand Up @@ -56,8 +58,10 @@ app.frame('/', (c) => {
})
})

serve({
fetch: app.fetch,
port: 3000,
})
console.log('Server is running on port 3000')
if (typeof Bun !== 'undefined') {

Check failure on line 61 in templates/bun/src/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / Types

Cannot find name 'Bun'.
Bun.serve({

Check failure on line 62 in templates/bun/src/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / Types

Cannot find name 'Bun'.
fetch: app.fetch,
port: 3000,
})
console.log('Server is running on port 3000')
}
Binary file added templates/cloudflare-worker/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions templates/cloudflare-worker/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Button, Frog, TextInput } from 'frog'
import { serveStatic } from 'frog/serve-static'

export const app = new Frog({
// Supply a Hub API URL to enable frame verification.
// hubApiUrl: 'https://api.hub.wevm.dev',
})

app.use(

Check failure on line 9 in templates/cloudflare-worker/src/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / Types

No overload matches this call.
'/*',
serveStatic({
root: './',
}),
)

app.frame('/', (c) => {
const { buttonValue, inputText, status } = c
const fruit = inputText || buttonValue
Expand Down
3 changes: 3 additions & 0 deletions templates/cloudflare-worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name = "frog-template"
compatibility_date = "2023-12-01"

[site]
bucket = "./public"

# [vars]
# MY_VARIABLE = "production_value"

Expand Down
Binary file added templates/default/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/default/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Button, Frog, TextInput } from 'frog'
import { serveStatic } from 'frog/serve-static'

export const app = new Frog({
// Supply a Hub API URL to enable frame verification.
// hubApiUrl: 'https://api.hub.wevm.dev',
})

app.use('/*', serveStatic({ root: './public' }))

Check failure on line 9 in templates/default/src/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / Types

No overload matches this call.

app.frame('/', (c) => {
const { buttonValue, inputText, status } = c
const fruit = inputText || buttonValue
Expand Down
1 change: 1 addition & 0 deletions templates/next/app/api/[[...routes]]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Binary file added templates/node/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/node/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { serve } from '@hono/node-server'
import { Button, Frog, TextInput } from 'frog'
import { serveStatic } from 'frog/serve-static'

export const app = new Frog({
// Supply a Hub API URL to enable frame verification.
// hubApiUrl: 'https://api.hub.wevm.dev',
})

app.use('/*', serveStatic({ root: './public' }))

Check failure on line 10 in templates/node/src/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / Types

No overload matches this call.

app.frame('/', (c) => {
const { buttonValue, inputText, status } = c
const fruit = inputText || buttonValue
Expand Down
1 change: 1 addition & 0 deletions templates/vercel/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Binary file added templates/vercel/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7beefe

Please sign in to comment.