running now
This commit is contained in:
parent
85cd083750
commit
c17bb05f0a
25 changed files with 156 additions and 114 deletions
34
src/index.ts
34
src/index.ts
|
|
@ -1,19 +1,18 @@
|
|||
import { AppDataSource } from "./data-source"
|
||||
import * as express from "express";
|
||||
import * as dotenv from "dotenv";
|
||||
import { Request, Response } from "express";
|
||||
import authRoutes from "./endpoints/AuthPoint"
|
||||
import userRoutes from "./endpoints/UserPoint";
|
||||
//import { recipePoint } from "./endpoints/RecipePoint";
|
||||
import {errorHandler} from "./middleware/errorHandler"
|
||||
import "reflect-metadata";
|
||||
import express, { NextFunction, Request, Response } from "express";
|
||||
import dotenv from "dotenv";
|
||||
import { AppDataSource } from "./data-source.js";
|
||||
import authRoutes from "./endpoints/AuthPoint.js";
|
||||
import userRoutes from "./endpoints/UserPoint.js";
|
||||
// import recipeRoutes from "./endpoints/RecipePoint.js";
|
||||
import { errorHandler } from "./middleware/errorHandler.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use(errorHandler);
|
||||
|
||||
|
||||
async function startServer() {
|
||||
try {
|
||||
// 1️⃣ Initialize database
|
||||
|
|
@ -27,21 +26,26 @@ async function startServer() {
|
|||
// 2️⃣ Setup routes
|
||||
app.use("/auth", authRoutes);
|
||||
app.use("/user", userRoutes);
|
||||
// app.use("/recipe", recipeRoutes);
|
||||
|
||||
app.get("*", (req: Request, res: Response) => {
|
||||
res.status(505).json({ message: "Bad Request" });
|
||||
console.log("auth and user routes added")
|
||||
app.get(/(.*)/, (req: Request, res: Response, next: NextFunction) => {
|
||||
res.status(400).json({ message: "Bad Request" });
|
||||
});
|
||||
console.log("Routes set up")
|
||||
|
||||
// 3️⃣ Start listening
|
||||
const PORT = parseInt(process.env.PORT || "4000", 10);
|
||||
const PORT = Number(process.env.PORT) || 4000;
|
||||
const HOST = process.env.HOST || "localhost";
|
||||
|
||||
app.listen(PORT, HOST, () => {
|
||||
console.log(`Server running on http://${HOST}:${PORT}`);
|
||||
console.log(`✅ Server running on http://${HOST}:${PORT}`);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error during Data Source initialization:", err);
|
||||
console.error("❌ Error during Data Source initialization:", err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Call the async start function
|
||||
startServer();
|
||||
startServer();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue