-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (42 loc) · 1.63 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors'); // Import the cors package
const registerRoute = require('./routes/register');
const loginRoute = require('./routes/login');
const getUserRoute = require('./routes/getUser')
const jobsRoute = require('./routes/jobs');
const removeJobRoute = require ('./routes/removeJob')
const getJobsRoute = require('./routes/getJobs');
const allowCors = require('./allowCors'); // Adjust the path if necessary
const applyRoute = require('./routes/apply');
const addBlogRoute = require('./routes/addBlog')
const getBlogsRouter = require('./routes/getBlogs');
const updateUserRouter = require('./routes/updateUser');
const announcementsRoute = require('./routes/announcements');
const app = express();
const port = process.env.PORT || 3001;
require('dotenv').config();
// Middleware
app.use(allowCors); // Apply allowCors middleware globally
app.use(bodyParser.json()); // Parse JSON bodies
// Routes
app.use('/register', registerRoute);
app.use('/login', loginRoute);
app.use('/getUser', getUserRoute);
app.use('/updateUser', updateUserRouter)
app.use('/addJob', jobsRoute);
app.use('/removeJob', removeJobRoute);
app.use('/getJobs', getJobsRoute);
app.use('/jobs/apply', applyRoute);
app.use('/addBlog', addBlogRoute);
app.use('/getBlogs', getBlogsRouter);
app.use('/announcements', announcementsRoute);
/* MONGOOSE SETUP */
const uri = process.env.MONGO_URL;
mongoose
.connect(uri)
.then(() => {
app.listen(port, () => console.log(`Server Port: ${port}`));
})
.catch((error) => console.log(`${error} did not connect`));