Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: isomorphic serveStatic #55

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' }))

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') {
Bun.serve({
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(
'/*',
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' }))

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' }))

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.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading