-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (41 loc) · 1.4 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
import express from 'express'
import cors from 'cors'
import dotenv from 'dotenv'
import { routerFiles } from './routes/files.js'
import { router } from './routes/file.js'
import { routerApiKey } from './routes/apiKey.js'
import { connectDb } from './db/dbConfig.js'
import swaggerUi from 'swagger-ui-express'
import path from 'path'
import { config } from './config/config.js'
import { errorHandler } from './middleware/errorHandler.js'
import { validateApiKey } from './middleware/validateApiKey.js'
import swaggerDocument from './swagger.json' assert { type: "json" };
dotenv.config()
const{MONGO_USERNAME,MONGO_DATABASE,MONGO_IP,MONGO_PORT,MONGO_PASSWORD}=config
const app= express()
app.use(cors({origin:'*'}))
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const PORT= process.env.FILE_PORT
app.enable("trust proxy")
app.use(express.json())
app.use("/ping", (req,res)=>{
res.status(200).send("Service is up")
});
app.use("/generate-api-key",routerApiKey)
app.use(validateApiKey)
app.use('/file',router)
app.use("/files",routerFiles)
app.use(errorHandler)
const mongoUrl2="mongodb+srv://amschel:[email protected]"
connectDb(mongoUrl2).
then(()=>{
console.log('db connected successfully')
app.listen(PORT, ()=>{
console.log(`server up and running on ${PORT} `)
})
}).
catch((e)=>{
console.log(mongoUrl)
console.log(e.message)
})