-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
40 lines (32 loc) · 1016 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
32
33
34
35
36
37
38
39
40
var http = require('http');
var fs = require('fs');
var path = require('path');
var express = require('express');
var request = require("request");
var bodyParser = require('body-parser');
var mkdirp = require('mkdirp');
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('view engine', 'html');
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.all('/index', function(req, res) {
res.sendFile('index.html', {
root: __dirname + '/public'
})
});
app.get('/saveTile', function(req, res) {
var paths = req.query.path.split('/');
paths.length = paths.length - 1;
mkdirp(__dirname + '/' + paths.join('/'), function(err) {
err && console.log(err);
request(req.query.url).pipe(fs.createWriteStream(__dirname + '/' + req.query.path));
});
res.json({
success: true
})
});
var server = http.createServer(app);
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});