-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathserver.js
31 lines (29 loc) · 826 Bytes
/
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
const http = require('http')
const path = require('path')
const fs = require('fs')
const exmaplePath = path.join(__dirname, 'index.html')
http
.createServer((req, res) => {
const url = req.url
if (url !== '/') {
let basePath = __dirname
if (url === '/hevc_test_moov_set_head_16s.mp4') {
basePath = path.join(__dirname, '..', 'example')
}
const staticFilePath = path.join(basePath, url)
if (fs.existsSync(staticFilePath)) {
fs.readFile(staticFilePath, (err, data) => {
if (err) console.log(err)
res.end(data)
})
}
} else {
fs.readFile(exmaplePath, (err, data) => {
if (err) console.log(err)
res.end(data)
})
}
})
.listen(3000, () => {
console.log('server work at: http:localhost:3000')
})