-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservelocally.js
110 lines (86 loc) · 2.87 KB
/
servelocally.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var express = require('express')
, request = require('request')
, http = require('http');
var app = express();
app.use(express.logger('dev'));
// ajax stuff ******************
app.get('/ajax/login', function(req, res) {
// http://coastmap.com/ecop/wms.aspx?request=GetUserInfo&version=1.1.1&username=asademo&pw=asademo55
var getreq = 'http://coastmap.com/ecop/wms.aspx?request=GetUserInfo&version=1.1.1';
// add get vars
getreq += '&username=' + req.query.username;
getreq += '&pw=' + req.query.pw;
request(getreq, function(err, response, body) {
if (err) throw err;
res.send(body);
});
});
app.get('/ajax/stations/getstations', function(req, res) {
request('http://imms.ehihouston.com/stations/JSON/', function(err, response, body) {
if (err) throw err;
res.type('json');
res.send(body);
});
});
app.get('/ajax/stations/latest', function(req,res) {
request('http://imms.ehihouston.com/stations/'+req.query.sid+'/latest/JSON/?metric=True',
function(err, response, body) {
if (err) throw err;
res.type('json');
res.send(body);
}
);
});
// coastmap proxy
app.get('/ajax/wmsproxy', function(req, res) {
var url = '/ecop/wms.aspx'
+ req.originalUrl.substr(req.originalUrl.indexOf('?'));
var request = http.get({
hostname: 'coastmap.com',
path: url,
}, function(response) {
// console.log('STATUS: ' + response.statusCode);
// console.log('HEADERS: ' + JSON.stringify(response.headers));
var bodychunks = [];
response.on('data', function(chunk) {
bodychunks.push(chunk);
// console.log('got data, chunk ' + bodychunks.length.toString());
}).on('end', function() {
res.type('png');
res.send(Buffer.concat(bodychunks));
});
});
request.on('error', function(e) {
console.log('http error: ' + e.message);
});
});
// asascience proxy
// http://gis.asascience.com/ArcGIS/rest/services/oilmap/oceansmap/MapServer
app.get('/ajax/asaproxy/export', function(req, res) {
var url = '/ArcGIS/rest/services/oilmap/oceansmap/MapServer/export'
+ req.originalUrl.substr(req.originalUrl.indexOf('?'));
var request = http.get({
hostname: 'gis.asascience.com',
path: url,
}, function(response) {
// console.log('STATUS: ' + response.statusCode);
// console.log('HEADERS: ' + JSON.stringify(response.headers));
var bodychunks = [];
response.on('data', function(chunk) {
bodychunks.push(chunk);
// console.log('got data, chunk ' + bodychunks.length.toString());
}).on('end', function() {
res.type('png');
res.send(Buffer.concat(bodychunks));
});
});
request.on('error', function(e) {
console.log('http error: ' + e.message);
});
});
// serve static files
app.use(express.static(__dirname + '/main'));
// start listening
app.listen('5100', function() {
console.log('Listening on port 5100');
});