-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·62 lines (47 loc) · 1.76 KB
/
server.js
File metadata and controls
executable file
·62 lines (47 loc) · 1.76 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
var express = require('express'),
app = express();
http = require('http');
var fs = require("fs");
httpServer = http.Server(app);
var path = require('path');
var exec = require('child_process').exec;
app.use('/public', express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.send('system')
});
app.get('/see/', function(req, res) {
exec('./record.sh',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
setTimeout(function() { var cur = + new Date();
console.log(cur);
res.send('<html> <head> <title>see</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> </head><body><p> </br></br></br></br> </br> </br> </br> <center><font size="12"><a class="w3-btn w3-green" href="http://192.168.0.198:3000/show?='+cur+'"'+'> Click to See Him <img src="http://192.168.0.198:3000/public/camera.svg" alt="Mountain View" style="width:100px;height:50px;"></a> </center></font></p> </body></html>'); }, 10000);
})
function nocache(req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
}
app.get('/show', nocache, sendContent);
function sendContent(req, res) {
var localPath = 'public/index.html';
var mimeType = '';
fs.readFile(localPath, 'utf8', function (err, contents) {
if (!err && contents) {
res.header('Content-Type', mimeType);
res.header('Content-Length', contents.length);
res.end(contents);
} else {
res.writeHead(500);
res.end();
}
});
}
console.log("go to browser :192.168.0.198:3000/see ");
app.listen(3000);