-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (27 loc) · 885 Bytes
/
Copy pathapp.js
File metadata and controls
35 lines (27 loc) · 885 Bytes
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
var express = require('express')
, httpProxy = require('http-proxy')
, path = require('path');
var proxy = new httpProxy.RoutingProxy();
var proxyOptions = {
host: 'api.openweathermap.org',
port: 80
};
var app = express();
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Accept, Origin, Referer, User-Agent, Content-Type, Authorization');
if ('OPTIONS' == req.method) {
res.send(200);
} else {
next();
}
};
app.configure(function() {
app.use(express.static(path.join(__dirname, 'public')));
app.use(allowCrossDomain);
});
app.all('/*', function (req, res) {
return proxy.proxyRequest(req, res, proxyOptions);
});
app.listen(3333);