Skip to content

Commit c2e77cd

Browse files
committed
api added for posts
1 parent d252757 commit c2e77cd

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

File renamed without changes.

src/api/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const express = require('express');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const app = express();
5+
const port = process.env.PORT || 3000;
6+
7+
app.use(express.static(path.join(__dirname, 'public')));
8+
9+
// Route to get the JSON data
10+
app.get('/posts/index.json', (req, res) => {
11+
fs.readFile(path.join(__dirname, 'public', 'posts', 'index.json'), 'utf8', (err, data) => {
12+
if (err) {
13+
res.status(500).send('Server Error');
14+
return;
15+
}
16+
res.header("Content-Type", "application/json");
17+
res.send(data);
18+
});
19+
});
20+
21+
app.listen(port, () => {
22+
console.log(`Server running on port ${port}`);
23+
});

vercel.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
2-
"rewrites": [
3-
{
4-
"source": "/posts/(.*)",
5-
"destination": "/posts/$1"
6-
},
7-
{
8-
"source": "/(.*)",
9-
"destination": "/"
10-
}
2+
"version": 2,
3+
"builds": [
4+
{ "src": "api/index.js", "use": "@vercel/node" },
5+
{ "src": "public/**/*", "use": "@vercel/static" }
6+
],
7+
"routes": [
8+
{ "src": "/api/(.*)", "dest": "/api/index.js" },
9+
{ "src": "/(.*)", "dest": "/public/$1" }
1110
]
1211
}
1312

0 commit comments

Comments
 (0)