bot-api/src/index.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

import express from "express";
import mongoose from "mongoose";
2023-12-27 16:07:32 +00:00
import listEndpoints from "express-list-endpoints";
import imageController from "./controllers/ImageController";
import authControler from "./controllers/AuthControler";
2023-12-25 11:15:19 +00:00
export const app = express();
app.use(express.json());
app.get("/", (_, res) => {
2023-12-27 19:41:35 +00:00
const endpoints = listEndpoints(app);
res.json({ endpoints });
});
app.get("/images", imageController.getAllImages);
2023-12-27 19:33:25 +00:00
app.post("/images", authControler.authorize, imageController.addImage);
2023-12-27 19:41:35 +00:00
app.post("/login", authControler.login);
const start = async () => {
2023-12-27 19:38:15 +00:00
// Set the default port to 8080, or use the PORT environment variable
2023-12-27 15:52:15 +00:00
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);
}
};
start();