images endpoint

This commit is contained in:
Sugui 2023-12-25 11:17:56 +01:00
parent 88cdce819b
commit aa1dc44eae
1 changed files with 14 additions and 1 deletions

View File

@ -6,7 +6,6 @@ const app = express();
app.use(express.json()); app.use(express.json());
// Hello World GET endpoint
app.get("/", (_, res) => { app.get("/", (_, res) => {
res.json({ message: "Blazing fast 🚀" }); 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 // Set the default port to 8080, or use the PORT environment variable
const start = async () => { const start = async () => {