new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Expo · Router · all subjects

file-based-routes

129 notes in this subject, read out of this brain and free to use. This is page 3 of 3.

Export API routes for production

Run `npx expo export --platform web` to create a server bundle in the **dist** directory for production deployment. To export only the server code without generating a website, use `npx expo export --platform web --no-ssg`.

Testing production build against local dev server

Export the production server with `npx expo export`, then host it locally with `npx expo serve`. Set the `origin` in **app.json** to `http://localhost:8081` (or the appropriate port), then build the app with `EXPO_NO_DEPLOY=1 npx expo run:ios --configuration Release` to test against the local server.

Bun server adapter for Expo API routes

Example server entry file for Bun using `expo-server/adapter/bun`: ```ts server.ts import { createRequestHandler } from 'expo-server/adapter/bun'; const CLIENT_BUILD_DIR = `${process.cwd()}/dist/client`; const SERVER_BUILD_DIR = `${process.cwd()}/dist/server`; const handleRequest = createRequestHandler({ build: SERVER_BUILD_DIR }); const port = process.env.PORT || 3000; Bun.serve({ port, async fetch(req) { const url = new URL(req.url); const staticPath = url.pathname === '/' ? '/index.html' : url.pathname; const file = Bun.file(CLIENT_BUILD_DIR + staticPath); if (await file.exists()) return new Response(await file.arrayBuffer()); return handleRequest(req); }, }); ```

Express server adapter for Expo API routes

Example server entry file for Express using `expo-server/adapter/express`: ```ts server.ts const path = require('path'); const { createRequestHandler } = require('expo-server/adapter/express'); const express = require('express'); const compression = require('compression'); const morgan = require('morgan'); const CLIENT_BUILD_DIR = path.join(process.cwd(), 'dist/client'); const SERVER_BUILD_DIR = path.join(process.cwd(), 'dist/server'); const app = express(); app.use(compression()); app.disable('x-powered-by'); process.env.NODE_ENV = 'production'; app.use(express.static(CLIENT_BUILD_DIR, { maxAge: '1h', extensions: ['html'] })); app.use(morgan('tiny')); app.all('/{*all}', createRequestHandler({ build: SERVER_BUILD_DIR })); const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`Express server listening on port ${port}`); }); ```

Native deployment with automatic server linking

For native apps, automatic server deployment can be enabled by setting `EXPO_UNSTABLE_DEPLOY_SERVER=1` in the `.env` file. This ensures correct versioning during native builds by automatically deploying a versioned server and linking it. The `origin` field must not be set in **app.json** for this to work, and **app.config.js** is not yet supported.

Netlify configuration for Expo API routes

Example **netlify.toml** configuration: ```yaml netlify.toml [build] command = "expo export -p web" functions = "netlify/functions" publish = "dist/client" [[redirects]] from = "/*" to = "/.netlify/functions/server" status = 404 [functions] included_files = ["dist/server/**/*"] [[headers]] for = "/dist/server/_expo/functions/*" [headers.values] "Cache-Control" = "public, max-age=60, s-maxage=60" ``` Create **netlify/functions/server.ts** with the `createRequestHandler` from `expo-server/adapter/netlify`.

Vercel configuration v3 for Expo API routes

Example **vercel.json** v3 configuration: ```json vercel.json { "buildCommand": "expo export -p web", "outputDirectory": "dist/client", "functions": { "api/index.ts": { "runtime": "@vercel/node@5.1.8", "includeFiles": "dist/server/**" } }, "rewrites": [ { "source": "/(.*)", "destination": "/api/index" } ] } ``` Create **api/index.ts** using `createRequestHandler` from `expo-server/adapter/vercel`.

API routes limitation: no dynamic imports

API routes are bundled into a single file, which means external dependencies that are not bundled with the server cannot be used. Libraries like `sharp` that include platform binaries are not supported. This limitation is expected to be addressed in a future version.

API routes limitation: ESM not supported

All API route code is transpiled to CommonJS (`require`/`module.exports`). ESM is not currently supported, though writing code using ESM syntax is recommended as support will be added in the future.

Give your agent this brain