-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (30 loc) · 1.04 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 videosRouter from "./routes/videos.js";
import cors from "cors";
import "dotenv/config";
import path from "path";
import { fileURLToPath } from "url";
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(cors());
app.use(express.json());
app.use("/images", express.static(path.join(__dirname, "public", "images")));
app.use("/videos", express.static(path.join(__dirname, "public", "videos")));
const PORT = process.env.PORT || 8080;
app.get("/", (req, res) => {
res.send("Homepage");
});
app.use("/videos", videosRouter);
app.use((err, req, res, next) => {
if (err.code === "LIMIT_FILE_SIZE") {
return res.status(400).json({ message: "File size exceeds limit." });
} else if (err.code === "INVALID_FILE_TYPE") {
return res.status(400).json({ message: err.message });
} else {
return res.status(500).json({ message: "Internal Server Error" });
}
});
app.listen(PORT, () => {
console.log(`App is running on port ${PORT}`);
});