Hi @amyegan, thank you for the quick reply!
I don’t have a full minimal code example, but I can provide steps to reproduce:
- Create a new react-native project (typescript). No need to write any front-end code.
- React Native should come with expo as the build system, and with the configurations for vercel.json set up + package.json, you should be able to run
vercel dev
to see the local server running.
- Create a vercel project and link with the react native project, entering in the custom build and development settings (in the screen shot)
- Running
vercel
will deploy to the vercel project.
After deploying the vercel project, visiting the url https://{project_url}/api/health
should result in a 200 json response.
However… if you were to run this project locally with vercel dev
and then visit the link with http://localhost:8081/api/health
, it will result in a Unmatched Route
error.
Here’s the code for health.ts
, it’s just a simple API that should return a JSON 200 response always. Make sure to create this file with the path my-project/api/health.ts
export async function GET(request: Request) {
return new Response(JSON.stringify({ status: 'ok' }), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
}
The build and development settings are custom, here’s a screen shot:
Here’s my vercel.json:
{
"buildCommand": "expo export -p web",
"outputDirectory": "dist",
"cleanUrls": true,
"framework": null,
"rewrites": [
{
"source": "/api/:path*",
"destination": "/api/:path*"
},
{
"source": "/:path*",
"destination": "/"
}
]
}
and my part of my package.json without the dependencies:
{
"name": "xlate",
"main": "expo-router/entry",
"version": "1.0.0",
"scripts": {
"start": "expo start",
"reset-project": "node ./scripts/reset-project.js",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint",
"build": "expo export:web"
},
... deps ...