images endpoint
This commit is contained in:
parent
88cdce819b
commit
aa1dc44eae
15
src/index.ts
15
src/index.ts
|
@ -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 () => {
|
||||||
|
|
Loading…
Reference in New Issue