diff options
Diffstat (limited to 'backend/src/index.js')
-rw-r--r-- | backend/src/index.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/backend/src/index.js b/backend/src/index.js new file mode 100644 index 0000000..6ee6435 --- /dev/null +++ b/backend/src/index.js @@ -0,0 +1,48 @@ +const express = require('express'); +const cors = require('cors'); +const path = require('path'); +const http = require('http'); +const connectDB = require('./config/database'); +const env = require('./config/env'); +const logger = require('./config/logger'); +const { notFound, errorHandler } = require('./middleware/error.middleware'); +const apiRoutes = require('./routes'); +const initializeSocket = require('./socket'); + +// Initialize express app +const app = express(); +const PORT = env.PORT; + +// Create HTTP server +const server = http.createServer(app); + +// Initialize Socket.IO +const io = initializeSocket(server); + +// Make io accessible to routes +app.set('io', io); + +// Connect to MongoDB +connectDB(); + +// Middleware +app.use(cors()); +app.use(express.json()); +app.use(logger); + +// Routes +app.get('/', (req, res) => { + res.json({ message: 'Welcome to Restaurant Management System API' }); +}); + +// API Routes +app.use('/api', apiRoutes); + +// Error handling middleware +app.use(notFound); +app.use(errorHandler); + +// Start the server +server.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); +});
\ No newline at end of file |