File size: 2,386 Bytes
8b105ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
//General
const path = require('path');
//Initialize Database
const {initializeDatabase} = require("./utils/setupDB");
initializeDatabase();
//Prefix Flag (Use or not)
const {useApiPrefix} = require('./config')
const fs = require('fs');
const path1 = '/app/backend/database';
if (fs.existsSync(path1)) {
console.log('The path exists');
} else {
console.log('The path does not exist');
}
//Refresh the holidays
const {refreshHolidays} = require("./controller/holidays");
refreshHolidays();
//Route Imports
const authRoutes = require('./routes/authRoutes'); // Import the auth routes
const availabilityRoutes = require('./routes/availabilityRoutes'); // Import availability routes
const subscriptionRoutes = require('./routes/subscriptionRoutes'); // Import subscription routes
const demoRequestRoutes = require('./routes/demoRequestRoutes'); // Import demo request routes
const contactRoutes = require('./routes/contactRoutes'); // Import contact routes
const applicantRoutes = require('./routes/applicantRoutes'); // Import applicant routes
const app = express();
app.use(express.json()); // To handle JSON request body
// Serve static files from the React build folder
app.use(express.static(path.join(__dirname, 'build')));
// Catch-all route to serve React's index.html for unknown routes
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Middleware to parse JSON body
app.use(bodyParser.json());
//Use CORS
app.use(cors());
// Routes - Dynamically add /api prefix if the flag is true
if (useApiPrefix) {
app.use('/api', authRoutes); // /api/auth
app.use('/api', subscriptionRoutes); // /api/subscribe
app.use('/api', availabilityRoutes); // /api/availability
app.use('/api', demoRequestRoutes); // /api/demo-request
app.use('/api', contactRoutes); // /api/contact
app.use('/api', applicantRoutes); // /api/applicant
} else {
app.use(authRoutes); // No prefix
app.use(subscriptionRoutes); // No prefix
app.use(availabilityRoutes); // No prefix
app.use(demoRequestRoutes); // No prefix
app.use(contactRoutes); // No prefix
app.use(applicantRoutes); // No prefix
}
const PORT = process.env.PORT || 7860;
app.listen(PORT, '0.0.0.0', () => console.log(`Server running on port: ${PORT}`)); |