Initial commit

This commit is contained in:
Vadher
2026-07-19 14:09:43 +05:30
parent 8bf2cda36c
commit ca4d5b3db6
15 changed files with 168424 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
const express = require("express");
const fs = require("fs").promises;
const urlStoreController = require("./../models/url_store_controller");
const healthStatusController = require("./../models/health_status_controller");
const urlPath = "./database/urls.json";
const router = express.Router();
const app = express();
app.use(express.json());
router.post("/url/register", async (req, res) => {
try {
const { url } = req.body;
if (!url) {
return res.status(400).json({ error: "URL is required" });
}
await urlStoreController.addUrl(url);
res.status(201).json({
message: "URL added successfully",
});
} catch (err) {
console.error(err);
res.status(500).json({
error: "Failed to add URL",
});
}
});
router.get("/url", async (req, res) => {
try {
const data = await fs.readFile(urlPath, "utf8");
const urls = JSON.parse(data);
res.json(urls);
} catch (err) {
res.status(500).json({
error: err.message,
});
}
});
module.exports = router;