mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
no message
This commit is contained in:
parent
7b3586b020
commit
e53005f4a1
9
saver/package.json
Normal file
9
saver/package.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "dat-gui-saver",
|
||||
"version": "0.0.0",
|
||||
"bin": {
|
||||
"saver": "saver.js"
|
||||
},
|
||||
"main": "saver.js",
|
||||
"preferGlobal": "true"
|
||||
}
|
36
saver/saver.js
Normal file
36
saver/saver.js
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
var filename = /\/([^/]+\.json)$/.exec(req.url);
|
||||
if (!filename) {
|
||||
filename = 'dat-gui.json';
|
||||
} else {
|
||||
filename = filename[1];
|
||||
}
|
||||
switch(req.method) {
|
||||
case 'GET':
|
||||
if (!fs.existsSync(filename)) {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
return
|
||||
}
|
||||
res.writeHead(200, {'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost'});
|
||||
res.end(fs.readFileSync(filename, 'utf8'));
|
||||
break;
|
||||
case 'POST':
|
||||
var data = '';
|
||||
req.on('data', function(d) {data += d;})
|
||||
req.on('end', function() {
|
||||
res.writeHead(200, {'Access-Control-Allow-Origin': 'http://localhost'});
|
||||
fs.writeFileSync(filename, data);
|
||||
res.end();
|
||||
})
|
||||
break;
|
||||
default:
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}
|
||||
}).listen(7999);
|
Loading…
Reference in New Issue
Block a user