-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
78 lines (51 loc) · 2.17 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
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
73
74
75
76
77
78
import * as dotenv from 'dotenv'
dotenv.config()
import express from 'express'
const app = express()
// import mongoose from 'mongoose'
// mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true, useUnifiedTopology: true });
// const db = mongoose.connection
// db.on('error', (error) => console.log(error))
// db.once('open', () => console.log('Connected to Database'))
import cors from 'cors'
app.use(cors())
app.use(express.json())
// app.get('/', (req, res) => {
// res.send('Job Portal Backend')
// })
import { authenticationMiddleware } from './middleware/auth.js'
// Student side auth api
import studentRegisterRouter from './routes/student/register.js'
app.use('/api/student/register', studentRegisterRouter)
import studentLoginRouter from './routes/student/login.js'
app.use('/api/student/login', studentLoginRouter)
// StartUp side auth api
import startUpRegisterRouter from './routes/startUp/register.js'
app.use('/api/startUp/register', startUpRegisterRouter)
import startUpLoginRouter from './routes/startUp/login.js'
app.use('/api/startUp/login', startUpLoginRouter);
app.use(authenticationMiddleware);
// Student side api
import studentJobsRouter from './routes/student/jobs.js'
app.use('/api/student/jobs', studentJobsRouter);
// StartUp side api
import startUpJobsRouter from './routes/startUp/jobs.js'
app.use('/api/startUp/jobs', startUpJobsRouter);
// Sending Client Files
// DO NO REMOVE BELOW TWO LINES, THEY ARE FOR FUTURE USE
// The below commented line is for the case if we want to directly serve the frontend as client files here itself
// import path from 'path';
// import { fileURLToPath } from 'url';
// const __filename = fileURLToPath(import.meta.url);
// const __dirname = path.dirname(__filename);
// // Serve the static files from the React app
// app.use(express.static(path.join(__dirname, 'client')));
// // Handles any requests that don't match the ones above
// app.get('*', (req, res) => {
// // res.sendFile(path.join(__dirname + '/client/index.html'));
// res.status(404).send("not found");
// });
const port = process.env.PORT || 3000
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})