So my application is Node, Express, GraphQL and MongoDB and is written in TS.
I’m triggering the vercel deployment using a github action. The deployment seems to working fine but it is not getting the serverless function to run.
Entry point of my application is src/server.ts
and in the build it is dist/src/server.js
But on the vercel dashboard it is not picking the serverless function but showing statis assets.
My vercel.json file
{
"version": 2,
"builds": [
{
"src": "dist/src/server.js",
"use": "@vercel/node",
"config": { "includeFiles": ["dist/**"] }
}
],
"routes": [
{
"src": "/(.*)",
"dest": "dist/src/server.js"
}
]
}
and my src/server.ts is attached as a file
//imports here
//some TS interfaces here
function createServer(): ServerSetup {
const app = express() // Express server
// * Middlewares here
const expressServer = http.createServer(app)
const apolloServer = new ApolloServer<CustomContext>({
typeDefs: typeDefs,
resolvers: resolvers,
cache: 'bounded',
})
return { app, expressServer, apolloServer }
}
async function startServer() {
const { app, expressServer, apolloServer } = createServer()
await connectDatabase()
// * Start Apollo servers
await apolloServer.start()
// * Apply middleware after the servers have started
// app.get('/', (_, res: Response) => {
// const routes = [process.env.BASE_URL + ':' + PORT + '/public', process.env.BASE_URL + ':' + PORT + '/protected']
// res.status(200).send(`<p>Server is up and running</p> <br> ${routes.map((el) => `<p>Route to <a href="${el}">${el}</a></p>`)} `)
// })
app.use(
'/graphql',
authMiddleware,
expressMiddleware(apolloServer, {
context: async ({ req, res }: { req: CustomRequest; res: Response }) => ({
req,
res,
user: req.user,
}),
}),
)
expressServer.listen(PORT, () => {
console.log(`[???? server] Server is running at http://localhost:${PORT}`)
})
const socketServer = new SocketServer(expressServer)
console.log('[???? socket] SocketServer has been started.')
return { expressServer, socketServer }
}
export { createServer, startServer }
startServer()
export default startServer