Skip to content

heineiuo/expo-adapter-workers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published