-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (55 loc) · 1.6 KB
/
server.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
const express = require("express");
const cors = require("cors");
const path = require("path");
const mongoose = require("mongoose");
const { dbConnect } = require("./db/dbConnect");
const morgan = require("morgan");
const workExperience = require("./routes/work.route");
const project = require("./routes/project.route");
const blogRoutes = require("./routes/blog.route");
const swaggerUi = require("swagger-ui-express");
const swaggerSpec = require("./swagger");
//importing environment variables
require("dotenv").config();
const app = express();
// middelwares
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// static public route
app.use("/public", express.static("public"));
const port = 8000 || process.env.PORT;
app.get("/", (req, res) => {
res
.status(200)
.json({ apiVersion: "1.0", author: "Pranjal Goyal", status: 200 });
});
// resume pdf route
app.get("/resume", (req, res) => {
const pdfPath = path.join(
__dirname + "/public/pdf/PranjalGoyal_ResumeFullStack_Feb2024.pdf"
);
res.sendFile(pdfPath, (err) => {
if (err) {
console.log(err);
res.status(500).send("An error occurred, unable to display the file");
}
});
});
//routes
app.use("/work", workExperience);
app.use("/project", project);
app.use("/blog", blogRoutes);
// server starting scrpit
app.listen(port || process.env.PORT, () => {
console.log(`Server running at http://localhost:${port}`);
});
const startServer = async () => {
try {
await dbConnect();
} catch (error) {
console.log(error);
}
};
startServer();