estatesfunding/ef-api/index.js

83 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2024-09-04 00:52:26 +00:00
import express from "express";
import mongoose from "mongoose";
2024-09-17 14:36:35 +00:00
import mysql from "mysql2";
2024-09-04 00:52:26 +00:00
import cors from "cors";
import morgan from "morgan";
import session from "express-session";
import userRouter from "./routes/user.js";
2024-09-12 08:11:07 +00:00
import propertyRouter from "./routes/property.js";
2024-09-17 14:36:35 +00:00
import mysqlRouter from "./routes/mysqlproperty.js";
2024-11-05 11:31:20 +00:00
import adminRouter from "./routes/admin.js"
2024-09-04 00:52:26 +00:00
import dotenv from "dotenv";
2024-11-05 11:35:00 +00:00
// import bcrypt from "bcryptjs";
// import adminModal from "./models/admin.js";
2024-09-04 00:52:26 +00:00
const app = express();
dotenv.config();
app.use(morgan("dev"));
app.use(express.json({ limit: "30mb", extended: true }));
app.use(express.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
2024-09-04 06:49:59 +00:00
// app.use(cors({
// origin: 'http://67.225.129.127:81', // Allow requests from your frontend
// methods: 'GET,POST', // Specify allowed methods
// }));
2024-09-10 14:38:47 +00:00
app.use(express.static('dist'));
2024-09-04 00:52:26 +00:00
app.use(
session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: true,
})
);
app.use("/users", userRouter);
2024-09-16 10:55:17 +00:00
app.use("/properties", propertyRouter);
2024-09-17 14:36:35 +00:00
app.use("/mysql", mysqlRouter); // Use MySQL routes
2024-11-05 11:31:20 +00:00
app.use("/admin", adminRouter);
2024-09-17 14:36:35 +00:00
2024-09-16 10:55:17 +00:00
2024-09-04 00:52:26 +00:00
app.get("/", (req, res) => {
res.send("Welcome to EF-API");
});
const port = process.env.PORT || 5000;
// Connect to the database
const dbConnectionPromise = mongoose.connect(process.env.DB_ACCESS, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
});
// Start HTTP server
const startHttpServer = () => {
app.listen(port, () => {
console.log(`Server is running on port ${port} (HTTP)`);
});
}; startHttpServer();
// Handle database connection success/failure
dbConnectionPromise
.then(() => {
2024-09-17 14:36:35 +00:00
console.log("Connected to the MONGO database");
2024-09-04 00:52:26 +00:00
})
.catch((error) => {
console.log(`${error} did not connect`);
});
2024-11-05 11:31:20 +00:00
2024-11-05 11:35:00 +00:00
// const createAdminUser = async () => {
// const hashedPassword = await bcrypt.hash("Uer$99#KKma-hi19", 10);
// const admin = new adminModal({ username: "admin", password: hashedPassword });
// await admin.save();
// console.log("Admin user created.", admin);
// mongoose.disconnect();
// };
2024-11-05 11:31:20 +00:00
2024-11-05 11:35:00 +00:00
// createAdminUser();
2024-11-05 11:31:20 +00:00