Skip to content

Commit ce86eea

Browse files
Add config for vercel
1 parent c632558 commit ce86eea

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const path = require("path");
66
const openApiSpec = require("../swagger/openapi.json");
77

88
const app = express();
9-
const PORT = process.env.PORT || 3000;
109

1110
app.use(cors());
1211
app.use(bodyParser.json());
@@ -28,12 +27,12 @@ app.get("/openapi.json", (req, res) => {
2827
res.sendFile(path.join(__dirname, "../swagger/openapi.json"));
2928
});
3029

31-
app.listen(PORT, () => {
32-
console.log(`Server is running on http://localhost:${PORT}`);
33-
console.log(
34-
`API documentation available at http://localhost:${PORT}/api-docs`
35-
);
36-
console.log(
37-
`OpenAPI JSON available at http://localhost:${PORT}/openapi.json`
38-
);
39-
});
30+
// Export the app for Vercel or start the server locally
31+
if (process.env.NODE_ENV !== "production") {
32+
const PORT = process.env.PORT || 3000;
33+
app.listen(PORT, () => {
34+
console.log(`Server is running locally at http://localhost:${PORT}`);
35+
});
36+
}
37+
38+
module.exports = app;

vercel.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": 2,
3+
"builds": [
4+
{
5+
"src": "src/index.js",
6+
"use": "@vercel/node"
7+
}
8+
],
9+
"routes": [
10+
{
11+
"src": "/(.*)",
12+
"dest": "src/index.js"
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)