Code Monkey home page Code Monkey logo

expo-adapter-workers's Introduction

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

expo-adapter-workers's People

Contributors

heineiuo avatar

Stargazers

Alex Turpin avatar  avatar Sélim avatar Yuki Ishikawa avatar Nikita Pilgrim avatar Abel Chalier avatar  avatar Kevin Rojas avatar 布谷 avatar Justin I. Nevill avatar Tangpriest avatar

Watchers

 avatar Justin I. Nevill avatar

Forkers

millsp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.