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(dev-server): support c.env.ASSETS for CF Pages #23

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

yusukebe
Copy link
Member

@yusukebe yusukebe commented Nov 8, 2023

Resolves #17

@yusukebe yusukebe force-pushed the feat/dev-server-pages-assets branch from 33e4c11 to 37b8f64 Compare November 8, 2023 09:19
@yusukebe yusukebe changed the title feat(dev-server): suport c.env.ASSETS for CF Pages feat(dev-server): support c.env.ASSETS for CF Pages Nov 8, 2023
@yusukebe
Copy link
Member Author

yusukebe commented Nov 8, 2023

Hi @yudai-nkt!

I was able to fix the env.ASSET.fetch issue with this PR. Could you review it?

@yudai-nkt
Copy link
Contributor

that's cool thanks! i'm afraid i won't have time right now, but will check this on the weekend.

@yudai-nkt
Copy link
Contributor

I tried this fix with the reproduction repo in #17 (comment), but unfortunately I'm still getting the following error:

✘ [ERROR] Error: Could not proxy request: TypeError: fetch failed

      at
  /Users/ynkt/src/github.com/yudai-nkt/hono-vite-plugin-with-env-assets/node_modules/wrangler/wrangler-dist/cli.js:108453:29
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async #handleLoopbackCustomService
  (/Users/ynkt/src/github.com/yudai-nkt/hono-vite-plugin-with-env-assets/node_modules/miniflare/dist/src/index.js:7798:24)
      at async #handleLoopback
  (/Users/ynkt/src/github.com/yudai-nkt/hono-vite-plugin-with-env-assets/node_modules/miniflare/dist/src/index.js:7842:20)

Vite config is as follows:

import { type UserConfig } from "vite";
import pages from "@hono/vite-cloudflare-pages";
import { defaultOptions } from "@hono/vite-dev-server";

// copied from packages/dev-server/src/dev-server.ts in this PR
import { devServer } from "./plugin";

export default {
  plugins: [
    pages(),
    devServer({
      exclude: [...defaultOptions.exclude, /^\/assets\/.+/],
      cf: { assets: true }
    }),
  ],
} satisfies UserConfig;

@yusukebe
Copy link
Member Author

@yudai-nkt

Weird. I've cloned it and tried to run it with this PR's version, and it works fine.

Screenshot 2023-11-12 at 21 17 42

By the way, I used the vite dev command without wrangler. Could you try it again?

@yudai-nkt
Copy link
Contributor

Uh, I was using wrangler pages dev -- vite and port 8788. vite dev and port 5173 work fine, thanks! IIUC, we don't need to directly call wrangler during development because the plugin takes care of binding and other stuff, is that correct?

@yusukebe
Copy link
Member Author

Great!

IIUC, we don't need to directly call wrangler during development because the plugin takes care of binding and other stuff, is that correct?

Yes, we should use only Vite.

@yusukebe
Copy link
Member Author

Okay! I'll ship it now.

@yusukebe yusukebe merged commit f2b383b into main Nov 13, 2023
1 check passed
@yusukebe yusukebe deleted the feat/dev-server-pages-assets branch November 13, 2023 21:02
@yudai-nkt
Copy link
Contributor

Hi @yusukebe, it looks like you published this PR as @hono/[email protected] but it should be @hono/vite-cloudflare-pages I suppose.

@yusukebe
Copy link
Member Author

Hi, @yudai-nkt .

Ah! The tag name was wrong! But, the npm package name is correct: https://www.npmjs.com/package/@hono/vite-cloudflare-pages. So you can use the v0.1.0 now.

@yudai-nkt
Copy link
Contributor

sorry, i meant @hono/vite-dev-server instead of cloudflare pages. latest release doesn't seem to include this pr: https://www.npmjs.com/package/@hono/vite-dev-server

@yusukebe
Copy link
Member Author

@yudai-nkt

Super sorry! I've published v0.2.0 of @hono/vite-dev-server, now.

@yudai-nkt
Copy link
Contributor

thanks, I'll try it tonight!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

c.env.ASSETS is undefined in dev server
2 participants