We are currently in process of turning our project into a Turborepo monorepo to have better control over shared dependencies and provide ways to extend the Express app with aditional routes from additional apps.
I am aware that there are multiple questions in this regard in the community but most have been closed without the issue being resolved properly.
Problem
The first issue is with the Express framework and the provided deployment guide. It just doesn’t work. The only way we are reliably able to deploy an Express app is by using the deprecated builds with a route in the vercel.json.
We are somewhat worried about the deprecation notice since this is the only reliable method and functions with the Express app being exported from a script in the api/ directory do not work.
{
"version": 2,
"trailingSlash": false,
"builds": [
{
"src": "/apps/xyz/server.js",
"use": "@vercel/node",
"config": {
"includeFiles": "public/**"
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/apps/xyz/server.js"
}
]
}
Current Configuration
As for the monorepo we have separate apps with the SAML dependencies in the apps/ directory. We import the xyz express app and the SAML app module in a saml-server.js script in the project root.
import app from '@geolytix/xyz-app/server';
import saml from '@geolytix/xyz-saml-app';
import express from 'express';
app.get(`${xyzEnv.DIR}/saml/metadata`, saml);
app.get(`${xyzEnv.DIR}/saml/logout`, saml);
app.get(`${xyzEnv.DIR}/saml/login`, saml);
app.get(`${xyzEnv.DIR}/saml/logout/callback`, saml);
app.post(
`${xyzEnv.DIR}/saml/logout/callback`,
express.urlencoded({ extended: true }),
saml,
);
app.post(
`${xyzEnv.DIR}/saml/acs`,
express.urlencoded({ extended: true }),
saml,
);
export default app;
We are able to deploy this script which will install the required dependencies from both apps imported in this script by referencing the script in a --local-config apps/saml/vercel.json which references the saml-server.js script in the root.
{
"version": 2,
"trailingSlash": false,
"builds": [
{
"src": "/saml-server.js",
"use": "@vercel/node",
"config": {
"includeFiles": "public/**"
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/saml-server.js"
}
]
}
This works but it doesn’t feel very intuitive. I am putting this out here for others who may be stuck getting an Express monorepo to work at all.
It would be great to get some best working practice in this regard from the Vercel engineers and we really would like to get a bit of confidence in regards to deprecated builds logic.