expo-adapter-workers
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

expo-adapter-workers

Expo Router with API Routes is insane! However Cloudflare Workers is not supported by Expo team yet. So this adapter comes!

Precondition

Your project is using expo-router with API Routes.

In app.json, you should have configuration like this:

{
  "expo": {
    "web": {
      "bundler": "metro",
      "output": "server"
    }
  }
}

Usage

Step 1: Install

npm install expo-adapter-workers wrangler

Step 2: Run expo export

npx expo export -p web

Step 3: Create entry file for cloudflare workers

worker.ts

import { createRequestHandler } from "expo-adapter-workers";

const requestHandler = createRequestHandler();

export default {
  async fetch(request: Request, env: any, ctx: { waitUntil: any }) {
    try {
      return await requestHandler(request, env, ctx);
    } catch (e) {
      let pathname = new URL(request.url).pathname;
      return new Response(`"${pathname}" not found`, {
        status: 404,
        statusText: "not found",
      });
    }
  },
};

Step 4: Create wrangler.toml

wrangler.toml

name = "example"
main = "worker.ts"

compatibility_date = "2024-03-08"

[site]
bucket = "./dist/client"

Step 5: Deploy to cloudflare workers

npx expo-adapter-workers // This is required!!!
npx wrangler deploy

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i expo-adapter-workers

Weekly Downloads

102

Version

1.0.4

License

MIT

Unpacked Size

11.6 kB

Total Files

16

Last publish

Collaborators

  • heineiuo