Files
IYLaw-Site/server/app.js
2025-07-15 13:34:30 -04:00

40 lines
1.1 KiB
JavaScript

console.log("starting server...");
import path from "path";
import {fileURLToPath} from "url";
import express from "express";
import cors from "cors";
import userRouter from "./routes/users.js";
import errorHandler from "./middlewares/ErrorHandler.js";
import dotenv from "dotenv";
dotenv.config();
import db from "./models/db.js";
try {
await db.pool.query('SELECT 1');
console.log('Database connection successful.');
} catch (err) {
console.error('Database connection failed:', err);
process.exit(1);
}
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
app.use(cors({
origin: ['https://ijylaw.li0nhunter.com', 'https://ijylaw.com', "https://www.ijylaw.com", "http://localhost:5173"],
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
credentials: true
}));
app.get('/', (req, res) => {
res.send("Hello! You've reached ijy law backend. Unless you are a developer, you probably shouldn't be here.");
});
app.use("/api/users", userRouter);
app.use(errorHandler);
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});