2023-12-31 11:11:22 +00:00
|
|
|
import express from "express";
|
|
|
|
import listEndpoints from "express-list-endpoints";
|
|
|
|
import imageController from "./controllers/ImageController";
|
|
|
|
import authControler from "./controllers/AuthControler";
|
|
|
|
import mongoose from "mongoose";
|
|
|
|
|
|
|
|
export const app = express();
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
app.get("/", (_, res) => {
|
|
|
|
const endpoints = listEndpoints(app);
|
|
|
|
res.json({ endpoints });
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get("/images", imageController.getAllImages);
|
2024-01-03 12:58:18 +00:00
|
|
|
app.get("/images/:id", imageController.getImageById);
|
2023-12-31 11:11:22 +00:00
|
|
|
app.post("/images", authControler.authorize, imageController.addImage);
|
|
|
|
app.post("/login", authControler.login);
|
|
|
|
|
|
|
|
export const startApp = async () => {
|
|
|
|
const port = process.env.PORT || 8080;
|
|
|
|
const mongo_uri: string = process.env.MONGODB_URI || "";
|
|
|
|
const mongo_user = process.env.MONGODB_USER;
|
|
|
|
const mongo_pass = process.env.MONGODB_PASS;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await mongoose.connect(mongo_uri, {
|
|
|
|
authSource: "admin",
|
|
|
|
user: mongo_user,
|
|
|
|
pass: mongo_pass,
|
|
|
|
});
|
|
|
|
app.listen(port, () =>
|
|
|
|
console.log(`Express server listening on port ${port}`)
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default app;
|