-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
66 lines (58 loc) · 1.77 KB
/
app.js
File metadata and controls
66 lines (58 loc) · 1.77 KB
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
const express = require("express");
const ejs = require("ejs");
const path = require("path");
const fs = require("fs");
const { cours, utilisateurs } = require("./data");
const session = require('express-session');
require('dotenv').config();
const app = express();
app.engine("html", ejs.__express);
app.use(session({
name: process.env.SESSION_NAME,
resave : false,
saveUninitialized : false,
secret : process.env.SESSION_SECRET,
cookie : {
maxAge : 1000 * 60 * 60 * 24,
secure : false,
}
}))
app.use(express.static(path.join(__dirname, "public")));
app.set("view engine", "html");
app.set("views", path.join(__dirname, "views"));
app.get("/", (req, res) => {
console.log(utilisateurs);
res.render("index", { cours });
});
app.get("/connexion", (req, res) => {
res.render("connexion");
});
app.get("/inscription", (req, res) => {
res.render("inscription");
});
app.get("/lectureVideo", (req, res) => {
res.render("lectureVideo");
});
app.get("/video", (req, res) => {
const range = req.headers.range;
if (!range) {
res.status(400).send("Require Range header");
}
const videoPath = "public/videos/drcmind_intro.mp4";
const videoSize = fs.statSync("public/videos/drcmind_intro.mp4").size;
const CHUNK_SIZE = 10 ** 6;
const start = Number(range.replace(/\D/g, ""));
const end = Math.min(start + CHUNK_SIZE, videoSize - 1);
const contentLength = end - start + 1;
const headers = {
"Content-Range": "bytes " + start + "-" + end + "/" + videoSize,
"Accept-Ranges": "bytes",
"Content-Length": contentLength,
"Content-Type": "video/mp4",
};
res.writeHead(206, headers);
const videoStream = fs.createReadStream(videoPath, { start, end });
videoStream.pipe(res);
});
app.listen(4001);
console.log("L'application tourne au port 4001");