diff --git a/posts/index.json b/public/posts/index.json similarity index 100% rename from posts/index.json rename to public/posts/index.json diff --git a/posts/pull_request_tutorial_for_beginners.md b/public/posts/pull_request_tutorial_for_beginners.md similarity index 100% rename from posts/pull_request_tutorial_for_beginners.md rename to public/posts/pull_request_tutorial_for_beginners.md diff --git a/src/api/index.js b/src/api/index.js new file mode 100644 index 0000000..4950405 --- /dev/null +++ b/src/api/index.js @@ -0,0 +1,23 @@ +const express = require('express'); +const fs = require('fs'); +const path = require('path'); +const app = express(); +const port = process.env.PORT || 3000; + +app.use(express.static(path.join(__dirname, 'public'))); + +// Route to get the JSON data +app.get('/posts/index.json', (req, res) => { + fs.readFile(path.join(__dirname, 'public', 'posts', 'index.json'), 'utf8', (err, data) => { + if (err) { + res.status(500).send('Server Error'); + return; + } + res.header("Content-Type", "application/json"); + res.send(data); + }); +}); + +app.listen(port, () => { + console.log(`Server running on port ${port}`); +}); diff --git a/vercel.json b/vercel.json index bb22fe6..e2b4f0d 100644 --- a/vercel.json +++ b/vercel.json @@ -1,13 +1,12 @@ { - "rewrites": [ - { - "source": "/posts/(.*)", - "destination": "/posts/$1" - }, - { - "source": "/(.*)", - "destination": "/" - } + "version": 2, + "builds": [ + { "src": "api/index.js", "use": "@vercel/node" }, + { "src": "public/**/*", "use": "@vercel/static" } + ], + "routes": [ + { "src": "/api/(.*)", "dest": "/api/index.js" }, + { "src": "/(.*)", "dest": "/public/$1" } ] } \ No newline at end of file