|
const express = require('express'); |
|
const bodyParser = require('body-parser'); |
|
const cors = require('cors'); |
|
|
|
const path = require('path'); |
|
|
|
|
|
const {initializeDatabase} = require("./utils/setupDB"); |
|
initializeDatabase(); |
|
|
|
|
|
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'); |
|
} |
|
|
|
|
|
const {refreshHolidays} = require("./controller/holidays"); |
|
refreshHolidays(); |
|
|
|
|
|
const authRoutes = require('./routes/authRoutes'); |
|
const availabilityRoutes = require('./routes/availabilityRoutes'); |
|
const subscriptionRoutes = require('./routes/subscriptionRoutes'); |
|
const demoRequestRoutes = require('./routes/demoRequestRoutes'); |
|
const contactRoutes = require('./routes/contactRoutes'); |
|
const applicantRoutes = require('./routes/applicantRoutes'); |
|
|
|
const app = express(); |
|
|
|
app.use(express.json()); |
|
|
|
|
|
app.use(express.static(path.join(__dirname, 'build'))); |
|
|
|
|
|
app.get('*', (req, res) => { |
|
res.sendFile(path.join(__dirname, 'build', 'index.html')); |
|
}); |
|
|
|
|
|
app.use(bodyParser.json()); |
|
|
|
|
|
app.use(cors()); |
|
|
|
|
|
if (useApiPrefix) { |
|
app.use('/api', authRoutes); |
|
app.use('/api', subscriptionRoutes); |
|
app.use('/api', availabilityRoutes); |
|
app.use('/api', demoRequestRoutes); |
|
app.use('/api', contactRoutes); |
|
app.use('/api', applicantRoutes); |
|
} else { |
|
app.use(authRoutes); |
|
app.use(subscriptionRoutes); |
|
app.use(availabilityRoutes); |
|
app.use(demoRequestRoutes); |
|
app.use(contactRoutes); |
|
app.use(applicantRoutes); |
|
} |
|
|
|
const PORT = process.env.PORT || 7860; |
|
app.listen(PORT, '0.0.0.0', () => console.log(`Server running on port: ${PORT}`)); |