-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (38 loc) · 1.2 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
import express from "express"
import dotenv from 'dotenv'
import mongoose from "mongoose"
import cors from "cors"
import bodyParser from "body-parser"
import userRoute from "./routes/userRoute.js"
import tweetRoute from "./routes/eventsRoute.js"
import repliesRoute from "./routes/repliesRoute.js"
import voteRoute from "./routes/voteRoute.js"
import usernameRoute from "./routes/usernameRoute.js"
let app = express()
dotenv.config()
const corsOption = {
origin: ['https://www.antivjti.tech','https://antivjti.tech'],
}
app.options('*', cors(corsOption))
app.use(cors(corsOption))
app.use(express.urlencoded({ extended: true }))
app.use(bodyParser.json({ limit: '1.5mb' }))
app.use(express.json())
app.use("/",usernameRoute)
app.use("/", userRoute)
app.use("/", tweetRoute)
app.use("/",repliesRoute)
app.use("/", voteRoute)
app.get('/',(req,res)=>{
res.json({message:'hello welcome to antivjti api server if you are seeing this then you are only allowed to access this!'})
})
try {
mongoose.connect(process.env.MONGODB_URI)
console.log(`database connected`)
app.listen(process.env.PORT, () => {
console.log(`now your server is running on port ${process.env.PORT}`)
})
}
catch (e) {
console.log(e.message)
}