Expected / pre-typescript
Pre-typescript express app hosted on vercel would route all traffic to my server.js properly rendering the home page at ‘/’ route. The site could then be navigated through all other endpoints and POST and GET data and views.
Current
Now, I am getting error 404. I have been trying so many different configs from reading the documentation. I have since installed vercel CLI so I can test more things instead of having to redeploy every time. The dist files are already compiled locally and cli vercel dev starts the app and shows it listening on port 3000 but when I open the app vercel dev crashes with a vercel 502 error and shows an error in the console that ports 3000 is already in use which makes me think that vercel cli uses port 3000 and when I send a request my app tries to run on 3000 to and crashes ? but I don’t know.
locally without vercel. npm run build , npm start, runs the project fine locally.
Current JSON
vercel.json
{
"builds": [
{
"src": "dist/server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "dist/server.js"
}
]
}
package.json
{
"name": "my-website",
"version": "1.0.0",
"description": "Landing page of my website. Meant to serve as a portal to my projects",
"type": "module",
"main": "./dist/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./dist/server.js",
"tsc": "tsc",
"copy-views": "cpy \"src/**/*.mustache\" dist --parents",
"build": "npm run tsc && npm run copy-views",
"type-check": "tsc -p tsconfig.json --noEmit"
},
"keywords": [],
"author": "Keegan Churchill",
"license": "MIT",
"dependencies": {
"@types/expr-eval": "^1.0.2",
"body-parser": "^1.20.3",
"dotenv": "^16.4.7",
"expr-eval": "^2.0.2",
"express": "^4.21.2",
"mustache-express": "^1.3.2",
"mysql2": "^3.11.5",
"nodemailer": "^6.9.16"
},
"devDependencies": {
"@types/express": "^5.0.0",
"@types/node": "^22.10.2",
"cpy-cli": "^5.0.0",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.7.2"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"rootDir": "./src",
"moduleResolution": "node",
"allowJs": false,
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": false,
"skipLibCheck": true
},
"include": ["src/**/*.ts"],
"exclude": ["dist", "node_modules"],
}
HERE IS THE CONFIG WHILE APP WAS WORKING ON VERCEL
working state (pre-typescript) vercel.json
{
"version": 2,
"builds": [
{
"src": "app/server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "app/server.js"
},
{
"src": "/public/(.*)",
"dest": "/public/$1"
}
]
}
git hub repo link
Typescript, Mustache, Express, MySQL