-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.js
61 lines (49 loc) · 1.67 KB
/
serve.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
var finalhandler = require('finalhandler'),
http = require('http'),
express = require('express'),
serveStatic = require('serve-static'),
pathHelper = require('path'),
ip = require('ip'),
port = 9001,
title = 'node-lucca',
argv = require('minimist')(process.argv.slice(2));
if (typeof localStorage === "undefined" || localStorage === null) {
var LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./scratch');
}
localStorage.setItem('cameraCalib', 'myFirstValue');
console.log(localStorage.getItem('myFirstKey'));
var app = express();
port = argv.port || port;
process.title = argv.title || title;
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Serve up public/ftp folder
app.use(serveStatic(pathHelper.join(__dirname, 'app'), {'index': ['index.html', 'index.htm']}));
app.use('/camcalib/:calibration', function (req, res, next) {
console.log('Request Type:', req.method);
/*console.log('Request id:', req.params.calibration);*/
if(req.method == 'POST'){
if(req.params.calibration){
localStorage.setItem('camcalib', req.params.calibration);
}
res.status(200).end();
next();
}
});
app.get('/camcalib/', function(req, res){
res.status(200);
res.json(localStorage.getItem('camcalib'));
});
// Create server
/*var server = http.createServer(function(req, res) {
var done = finalhandler(req, res);
serve(req, res, done);
});*/
// Listen
//server.listen(port);
app.listen(port);
console.log('server listen on: http://' + ip.address() + ':' + port);