kios-webapp/apps/api/src/server.ts

40 lines
811 B
TypeScript
Raw Normal View History

2024-03-07 14:31:41 +00:00
import express from "express";
import payload from "payload";
const app = express();
// Redirect root to Admin panel
app.get("/", (_, res) => {
res.redirect("/admin");
});
2024-03-08 16:23:34 +00:00
const PORT = Number(process.env.PAYLOAD_PORT) ?? 3000;
const HOST = process.env.PAYLOAD_ADDRESS ?? 'localhost';
2024-03-08 16:06:23 +00:00
2024-03-07 14:31:41 +00:00
const start = async () => {
// Initialize Payload
await payload.init({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app,
onInit: async () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
},
mongoOptions: {
dbName: process.env.DB_NAME,
},
});
// Add your own express routes here
2024-03-08 16:06:23 +00:00
app.listen(
PORT,
HOST,
() => {
console.log(`Server running at http://${HOST}:${PORT}/`);
}
);
2024-03-07 14:31:41 +00:00
};
start();