-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
33 lines (27 loc) · 963 Bytes
/
index.js
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
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const PORT = process.env.PORT || 8080;
const { connectWithDatabase } = require("./db");
const app = express();
connectWithDatabase().then(() => {
app.listen(PORT, () =>
console.log(`Server is running at PORT : ${PORT}`)
);
});
// Middlewares
app.use(cors());
// Parse URL-encoded bodies (as sent by HTML forms)
app.use(express.urlencoded({ extended: true }));
// Parse JSON bodies (as sent by API clients)
app.use(express.json());
// app.use(require('./middlewares/auth.middelware'));
// Routes
const codeRoute = require('./routes/code.routes');
const authRoute = require('./routes/user.routes');
const blogRoute = require('./routes/blog.routes');
app.use('/api/code', codeRoute);
app.use('/api/blog', blogRoute);
app.use('/auth', authRoute);
app.use('/', (_req, res) => res.send('Backend is alive !!'));