(edited)
Hi! I'm trying to deploy a simple api with express. I have my entrypoint on /api/index.ts
// /api/index.tsimport app from '../src/app';export default app;The app for my api is on /src/app.ts
// src/app.tsimport express from 'express';import cors from 'cors';import { OpenAIProvider } from './providers/OpenAIProvider';import chatRouter from './routes/chat';
const app = express();
// Middlewareapp.use(cors());app.use(express.json());app.use(express.static('public'));
// Crear instancia del providerconst openAIProvider = new OpenAIProvider(process.env.OPENAI_API_KEY || '');
// Usar el router directamente ya que tiene su propia instancia del providerapp.use('/api/chat', chatRouter);
const PORT = process.env.PORT || 3000;app.listen(PORT, () => { console.log(`Server running on port ${PORT}`);});
export default app;Also, I have a simple html file with some vanilla js to test the API on /public/index.html
After deploy, the index.html interface is accesible but when I try to use the api I have this error on log section.
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/src/providers/OpenAIProvider' imported from /var/task/src/app.jsMy tsconfig.json
{ "compilerOptions": { "target": "ES2020", "module": "ES2020", "moduleResolution": "node", "outDir": "./dist", "strict": true, "esModuleInterop": true, "baseUrl": "." }, "include": [ "api/**/*", "src/**/*" ], "exclude": ["node_modules"]}My vercel.json
{ "version": 2, "builds": [ { "src": "src/app.ts", "use": "@vercel/node", "config": { "includeFiles": [ "src/**/*", "tsconfig.json" ] } }, { "src": "public/**", "use": "@vercel/static" } ], "routes": [ { "src": "/api/(.*)", "dest": "src/app.ts" }, { "src": "/(.*)", "dest": "public/$1" } ]}I will apreciate a lot any help from the comunity. thanks in advance!