From aa1dc44eaed56e87d67ded0041fdb5dc8d5f525c Mon Sep 17 00:00:00 2001 From: Sugui Date: Mon, 25 Dec 2023 11:17:56 +0100 Subject: [PATCH] images endpoint --- src/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 10401fc..cc1c227 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ const app = express(); app.use(express.json()); -// Hello World GET endpoint app.get("/", (_, res) => { res.json({ message: "Blazing fast 🚀" }); }); @@ -20,6 +19,20 @@ app.get("/images", async (req, res) => { } }) +app.post("/images", async (req, res) => { + try { + // Should add auth here before doing stuff + // Thowing a 401 if not auth provided + // throwing a 403 for incorrect auth + const image = await ImageModel.create(req.body); + res.json(image); + } catch (error) { + // Should return 409 Conflict for existing urls + // Should return 500 For other server errors + res.status(500).json({ message: error }); + } +}) + // Set the default port to 8080, or use the PORT environment variable const start = async () => {