My meteor server will fetch data from another source on Internet. The request has to go via a proxy. How can I specify the proxy server for server-side HTTP.call's?
You could easily make all HTTP.* calls through a proxy if only Meteor developers accepted my pull request to pass through options like proxy to the request module, on which the HTTP package is based.
Please comment on this GitHub issue to ask for that.
UPDATE: Since the Meteor devs refused to implement that change, I published an Atmosphere package that lets you transmit to Node (i.e. to the request module) any options you want.
Check out http-more on Atmosphere.
Found a solution for my problem.
I'm using Windows and could not find a way to set a default proxy for the OS as Serkan mentioned. Setting proxy server in Internet Explorer internet options LAN settings did not work. Settings proxy in winHTTP did not work. Anyone else know how to do it?
The most reasonable would be that Node read a environment variable and used that. So, I created an environment variable "HTTP_PROXY" and to see if node would read it I tried:
D:\Appl\.meteor\tools\a5dc07c9ab\bin>node -e "console.log(process.env.http_proxy)"
and it did output my variable. But, when trying to make a http.get() request directly within Node it failed. Node is obviously not using that variable ...
The conclusion of that is that I have to explicitly set the proxy in my app, but that is not possible with Meteor HTTP. Instead I could use the request module (that Meteor HTTP is using) and set the proxy. Not the ideal solution, because my app has to know about the proxy, but ok for my purpose.
if (Meteor.isServer) {
var request = Npm.require("request");
var makeRequest = Meteor._wrapAsync(thirdLibMakeRequest);
function thirdLibMakeRequest(options, callback) {
options.proxy = "http://myProxyServer:8080";
request(options, callback);
};
var response = makeRequest({ url: "http://UrlToSomeSite" });
}
Include the request module
Wrap the 3rd-lib async method so we can use it in Meteor
set the proxy property of the request module
use makeRequest to make requests.
Since the platform your meteor app will be running on will be behind the proxy as a whole, you'll be needing proxy access generally anyway.
Therefore, you can set your platform (os) up to connect to the proxy server by default, therefore Meteor will not necessarily know/care about the presence of a proxy since it will be transparent to it.
Related
I know you can specify a proxy via requests in praw using the environmental variable. I have had success doing so.
However, when building a custom session and specifying the the proxy address like so:
s = Session()
proxies = { 'https': 'https://72.35.40.34:8080'}
s.proxies.update(proxies)
# praw.ini holds praw_bot_name oauth details
bot = praw.Reddit(praw_bot_name, requestor_kwargs={'session': s})
print(bot._core._requestor._http.proxies)
The proxy will not take. The correct address shows up in this print statement, but via wireshark, I can see that the proxy is not actually in effect.
Does anyone know what might be going on here?
okay - so the above should actually work. I had a mistake elsewhere in my code which was causing my requests to run through my readonly reddit instance (which I was not defining a proxy for).
Will consider removing this question if others think it is not very useful.
I am creating a REST API in Go, and I want to build URLs to other resources in my replies.
Based on the http.Response I can get the Host and URL.
However, how would I go about getting the transport scheme used by the server? http or https?
I attemped to check if server.TLSConfig is nil and then assuming it is using http since it says this in the documentation for http.Server:
TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS
But it turns out this exists even when I do not run the server with ListenAndServeTLS.
Or is this way of building my URLs the wrong way of doing things? Is there some other normal way of doing this?
My preferred solution when running http and https is just to run a simple listener on :80 that redirects all traffic to https. Then any real traffic can be assumed to be https.
Alternately I believe you can access a request's URL at req.URL.Scheme to see the protocol.
Or do you mean for the entire application? If you accept configuration to switch between http and https, then can't you look at that and see which they chose? I guess I'm missing some context maybe.
It is also common practice for apps to take a baseURL via flag or config to generate external urls with.
One of the really cool things about Nginx is that you can take control of what it does by injecting Lua script at various phases of request processing. I have successfully used the rewrite_by_lua/file directive to examine the body of the incoming request and inject extra request headers for downstream processing by PHP. e.g.
location /api{
rewrite_by_lua_file "/path/to/rewrite.lua";
lua_need_request_body "on";
}
and then in rewrite.lua
local uri = ngx.var.request_uri;
//examine the URI and inject additional headers
ngx.req.set_header('headerName','headerValue');
What I can also do at this stage is inject response headers. For example
local cookieData = "cookieName=value;path=/;";
ngx.header['Set-Cookie'] = cookieData;
No issues thus far but this is not quite what I want to do. The workflow I have in mind goes like this
Examine the URI & inject extra request headers.
My PHP scripts examine the extra request headers, process the incoming data as required and may inject extra response headers
I then want to examine the response headers in another Nginx Lua script and inject cookies at that stage.
Injecting extra response headers via my PHP script is no problem at all. I thought that in order to examine those extra headers I would just need to setup
location /api {
header_filter_by_lua_file "path/to/header.lua";
}
with header.lua doing things like
local cookieData = "cookieName=value;path=/;";
ngx.header['Set-Cookie'] = cookieData;
The principle sounds perfect. However, I find that my header_filter_by_lua_file directives just get ignored - no errors reported in the Nginx log when I reload the configuration.
I must be doing something wrong here but I cannot see what it might be. I am using nginx 1.6.2 on Ubuntu 14.10 (x64). Nginx having been installed with apt-get install nginx-extras.
I'd be most grateful to anyone who might be able to explain how to get header_filter_by_* functioning correctly.
It's not a feature of vanilla nginx. You need to install openresty (instead of nginx).
See http://openresty.org/#Download and then http://openresty.org/#Installation
I have been working with Iron Router, and have been under the impression that the routes run on the server. But recently I was reading through the Accounts-Entry code and noticed that, although the routes are defined in "shared", the methods used to detect if the user is signed in only exists under "client".
This lead me to think about where routes actually run. Are they running on the client, server, both? What about "server" routes?
Have a look at the Server Side Routing section of the docs.
Defining routes and configuring the Router is almost identical on the server and the client. By default, routes are created as client routes. You can specify that a route is intended for the server by providing a where property to the route...
So by adding where: 'server' to the route, you allow it to run on the server. The advantage to defining the routes in a shared directory is that the server can then use the Router object to determine paths on the client (useful for things like generating email).
How do I get the http request header fields server side in a Meteor.js app?
For example in PHP one could use one of the following to determine what host or domain the request was on.
$_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME']
I know on the client side I can get that from
document.domain
and then I could pass it to the server.
But is there an easier way to get at least the HOST (something.domain.com) that the client made the request on?
After Meteor 0.7 you have to call on the server side
this.connection.httpHeaders
source http://www.meteorpedia.com/read/HTTP_Headers
Your timing is great, I just wrote the following package a few days ago.
https://atmospherejs.com/gadicohen/headers
Use like this:
js
var host = headers.get('host');
Though if you're only after the host, and you can get it from one of the other solutions provided here, they're preferable. The headers unfortunately have to make a round trip to the server and back, and the package is intended to get headers that aren't accessible any other way.
Meteor.absoluteUrl();
From the docs:
http://docs.meteor.com/#meteor_absoluteurl