-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpServer.js
123 lines (113 loc) · 2.75 KB
/
httpServer.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const express = require('express')
const {handleVideo}=require('./handleVideoExpress')
const {getVideoSizeByID,getVideobyID}=require('./database')
const fs=require('fs')
const app = express()
const port = 8080
app.get('/', (req, res) => {
console.log("index called")
fs.readFile(`./frontend/views.html`,(err,data)=>{
const header={
"Content-Length": data.length,
"Content-Type": "text",
}
console.log(header)
res.writeHead(200,header)
res.write(data)
res.end()
})
})
app.get('/main.css',(req,res)=>{
fs.readFile(`./frontend/main.css`,(err,data)=>{
const header={
"Content-Length": data.length,
"Content-Type": "text",
}
console.log(header)
res.writeHead(200,header)
res.write(data)
res.end()
})
})
app.get('/video.js',(req,res)=>{
fs.readFile(`./frontend/video.js`,(err,data)=>{
const header={
"Content-Length": data.length,
"Content-Type": "text",
}
console.log(header)
res.writeHead(200,header)
res.write(data)
res.end()
})
})
app.get('/thumbnail/0',(req,res)=>{
fs.readFile('./frontend/default.jpg',(err,data)=>{
const headers = {
"Content-Type": "image/jpg",
}
res.writeHead(200,headers)
res.write(data)
res.end()
})
})
app.get('/video/:id',(req,res)=>{
const id=parseInt(req.params.id)
if(!id){
return
res.end()
}
fs.readFile('./frontend/playVideo.html',(err,data)=>{
const headers = {
"Content-Length": data.length,
"Content-Type": "text",
}
res.writeHead(200,headers)
res.write(data)
res.end()
})
})
app.get('/favicon.ico',(req,res)=>{
fs.readFile('./frontend/favicon.ico',(err,data)=>{
const headers = {
"Content-Length": data.length,
"Content-Type": "image/ico",
}
res.writeHead(200,headers)
res.write(data)
res.end()
})
})
app.get('/logo.svg',(req,res)=>{
fs.readFile('./frontend/logo.svg',(err,data)=>{
const headers = {
"Content-Length": data.length,
"Content-Type": "image/svg+xml",
}
res.writeHead(200,headers)
res.write(data)
res.end()
})
})
app.get('/lupa',(req,res)=>{
fs.readFile('./frontend/lupa.png',(err,data)=>{
const headers = {
"Content-Length": data.length,
"Content-Type": "image/png",
}
res.writeHead(200,headers)
res.write(data)
res.end()
})
})
app.get('/search',(req,res)=>{
console.log(req.query.search)
})
app.get('/Database/video/:id',(req,res)=>{
const id=parseInt(req.params.id)
console.log(id)
handleVideo(req,res,async (from,to)=>{return (await getVideobyID(id)).content.slice(from,to)},async()=>{return await getVideoSizeByID(id)})
})
app.listen(port, () => {
console.log(`server starts at port ${port}`)
})