initial commit
This commit is contained in:
75
server/app.js
Normal file
75
server/app.js
Normal file
@ -0,0 +1,75 @@
|
||||
// server/app.js
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
// import multer from 'multer';
|
||||
// import path from 'path';
|
||||
import db from './models/db.js';
|
||||
import dotenv from 'dotenv';
|
||||
import emailController from "./controllers/emailController.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
/**@typedef {import("../client/src/DBRecord.ts").DBRecord} DBRecord */
|
||||
|
||||
console.log("Starting Server...");
|
||||
// test db connection
|
||||
try {
|
||||
await db.query("SELECT 1")
|
||||
console.log("DB connection successful")
|
||||
await db.get('users', {id: 1});
|
||||
console.log("Users table exists");
|
||||
|
||||
await emailController.withTimeout(emailController.transporter.verify(), 15000)
|
||||
.then(() => {
|
||||
console.log("Transporter is ready to send emails");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error verifying transporter:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Serve static files from the client build directory
|
||||
if (process.env.NODE_ENV !== 'development') app.use("/", express.static('../client/dist'));
|
||||
|
||||
/*const UPLOAD_FOLDER = path.join(process.cwd(), 'Scans');
|
||||
const storage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, UPLOAD_FOLDER);
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
cb(null, file.originalname);
|
||||
}
|
||||
});
|
||||
const upload = multer({storage});*/
|
||||
|
||||
// user routes
|
||||
import userRouter from './controllers/userController.js';
|
||||
|
||||
app.use('/api/users', userRouter);
|
||||
|
||||
// email routes
|
||||
app.use('/api/email', emailController.router);
|
||||
|
||||
// other routes
|
||||
|
||||
// Error handling middleware
|
||||
import errorHandler from './middleware/ErrorHandler.js';
|
||||
|
||||
app.use(errorHandler);
|
||||
// 404 handler
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({message: 'Route not found'});
|
||||
});
|
||||
|
||||
const PORT = process.env.PORT || 8000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Express server running on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user