Hi i try to run nodejs based proxy server
https://github.com/tec27/node-argyle
just found that
var argyle = require('argyle');
var server = argyle(8080, '127.0.0.1');
server.on('connected', function(req, dest) {
req.pipe(dest);
dest.pipe(req);
});
this code works on local browser can connect and run
tried to push it heroku and run
procfile :
worker: node app.js
Package.json
{
"name": "proxy",
"version": "1.0.0",
"dependencies": {
"argyle": "*"
},
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
}
}
do i miss anything
or try to open specified ports # heroku not allowed?
Related
I'm trying to deploy socket io + express server on heroku for a chat application but i am facing a trouble while deploying the server .
First this is my server code
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
users = [];
connections = [];
server.listen(process.env.PORT || 3000);
console.log('Server running...');
io.sockets.on('connection',function(socket){
connections.push(socket);
console.log('Connected %s sockets connected ', connections.length);
//Disconnect
socket.on('disconnect', function(data){
users.splice(users.indexOf(socket.username),1);
connections.splice(connections.indexOf(socket),1);
console.log('Disconneted : %s sockets connected',connections.length);
});
});
This is my package.json file
{
"name": "",
"version": "1.0.0",
"description": "chat application",
"main": "index.js",
"scripts": {
"start": "node index"
},
"author": "",
"license": "ISC",
"dependencies": {
"socket.io": "*",
"express": "*"
}
}
But I'm getting this error
Cannot GET /
Had the same problem (socket.io with express and react).
You can add to server this line:
app.use(express.static('some path to a static file'));
e.g.
app.use(express.static('client/build'))
works for me assuming in package.json has this line at "scripts":
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
This error has nothing wrong deployed application. Your app still waits for connection on port 3000 (or port from process.env.PORT). App responds "Cannot GET /" because you don't have any routes.
To see how routes can be implemented look at this -> https://expressjs.com/en/starter/hello-world.html
To see how connect using socket.io (client part) look at this -> https://socket.io/get-started/chat/#Integrating-Socket-IO
I am trying to use a postgresql database within nodejs server application hosted with Heroku.
This is my code for pg in app.js:
var pg = require('pg');
pg.defaults.ssl = true;
pg.connect(process.env.DATABASE_URL, function(err, client) {
if (err) throw err;
console.log('Connected to postgres!');
});
and npm declaration file package.json:
{
"name": "utility-app",
"version": "0.0.1",
"dependencies":
{
"ejs": "*",
"express": "3.3.x",
"pg": "6.0.1",
"simple-oauth2": "^0.7.0"
},
"engines":
{
"node": "0.10.x",
"npm": "1.2.x"
}
}
This is working in my local environment but when i push the code to Heroku the server crashed:
Screenshot of console demonstrating the crash
Thank you for your help,
JP
pg-pool is using an ES6 Promise, which isn't supported in the version of Node.js on your Heroku account, which is before 0.12.
You need to use a more modern version of Node.js, such as 4.x
This node.js proxy server works perfectly on my Ubuntu server (when I change the host to the server IP and the port to 8080). But this server fails on Openshift.
server.js:
var
url = require('url'),
http = require('http');
console.log ('------------------------------------------ ' );
var host = process.env.OPENSHIFT_NODEJS_IP || "localhost";
var port = process.env.OPENSHIFT_NODEJS_PORT || 80;
console.log(port + ' '+ host);
var d = require('domain').create();
d.on('error', function(err){
// handle the error safely
console.log('d.on error: '+err.message);
});
// catch the uncaught errors in this asynchronous or synchronous code block
d.run(function(){
// the asynchronous or synchronous code that we want to catch thrown errors on
http.createServer(function ( request, response ) {
console.log('request ' + request.url);
//-----------------------------------
request.pause();
var options = url.parse(request.url);
options.headers = request.headers;
options.method = request.method;
options.agent = false;
var connector = http.request(options, function(serverResponse) {
serverResponse.pause();
response.writeHeader(serverResponse.statusCode, serverResponse.headers);
serverResponse.pipe(response);
serverResponse.resume();
});
request.pipe(connector);
request.resume();
//-----------------------
}).listen(port, host);
});
This server logs 8080 127.13.56.111 as port and host. Getip.com gives 54.166.197.111 as the application url's (examplesite.rhcloud.com) ip address.
When I ping the application url I get this ip: 10.30.224.111
As my LAN proxy settings in the browser I used all kinds of combinations like:
54.166.197.111 80
127.13.56.111 8080
10.30.224.111 80
None of them work. My http requests form the browser, after changing the LAN proxy settings, don't get to my server. It doesn't log these requests.
How can I reach the server? What do I have to change in the script to make this proxy server work on openshift? (Or maybe you know an answer for appfog.)
Here my package.json:
{
"name": "OpenShift-Sample-App",
"version": "1.0.0",
"description": "OpenShift Sample Application",
"keywords": [
"OpenShift",
"Node.js",
"application",
"openshift"
],
"author": {
"name": "OpenShift",
"email": "ramr#example.org",
"url": "http://www.openshift.com/"
},
"homepage": "http://www.openshift.com/",
"repository": {
"type": "git",
"url": "https://github.com/openshift/origin-server"
},
"engines": {
"node": ">= 0.6.0",
"npm": ">= 1.0.0"
},
"dependencies": {
"domain": "0.0.0"
},
"devDependencies": {},
"bundleDependencies": [],
"private": true,
"main": "server.js"
}
With OpenShift Online, there is a reverse proxy between your gear and the internet. Here is a diagram that might be of use https://help.openshift.com/hc/en-us/articles/203263674-What-external-ports-are-available-on-OpenShift-. So while your OPENSHIFT_NODEJS_IP/PORT environment variables may report those IP's their not going to be directly accessible to the outside.
I created a node app in openshift, I connected through SSH, and I was able to push my code and I could change the server.js code for a simple hello world.
Server.js
#!/bin/env node
var http = require('http');
var serverIp = process.env.OPENSHIFT_NODEJS_IP;
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
//creating server
var server = http.createServer(function(req, res) {
res.writeHead('Content-Type', 'text/plain');
res.end('Simple example!!');
});
//listening
server.listen(port, serverIp, function() {
console.log('Server started on port ' + port + ' IP: ' + serverIp);
});
When push this new code, I'm not getting any errors.
And this is the package.json file
{ "name": "Hello_world",
"version": "1.0.0",
"description": "Hello world",
"engines": {
"node": ">= 0.6.0",
"npm": ">= 1.0.0"
},
"devDependencies": {},
"bundleDependencies": [],
"private": true,
"scripts": {
"start" : "node server.js"
},
"main": "server.js"
}
When I do this, the application gets very very slow (like 2/3 minutes of waiting), here's the link.
[http://avalecia-minisis.rhcloud.com/]enter code here1
But when I change the code for the original, everything's fine... :/
I don't see where the issue could be.
When deploying to OpenShift, your application's build process can be optimized (or tuned) in a variety of ways.
If you'd like to minimize downtime between deploys, you can try enabling the hot_deploy feature:
mkdir .openshift ; mkdir .openshift/markers ; touch .openshift/markers/hot_deploy
git add .openshift/markers/hot_deploy
git commit -m "enabling the hot_deploy marker to minimize downtime on OpenShift"
git push
Checking in your node_modules folder can also have a major impact on build time.
Turning on NPM_CONFIG_PRODUCTION is another approach that may help (see : Run npm install --production on OpenShift)
We'd like to surf the internet through a node.js proxy on appfog.
We tried this code:
proxy2a.js:
var http = require('http');
var port = process.env.VCAP_APP_PORT || 8080;
console.log ('the portnumber is: '+ port) ;
http.createServer(function(request, response) {
var proxy = http.createClient(80, "checkip.dyndns.org");
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.on('response', function (proxy_response) {
proxy_response.pipe(response);
response.writeHead(proxy_response.statusCode, proxy_response.headers);
console.log(proxy_response.statusCode) ;
});
request.pipe(proxy_request);
}).listen(port);
package.json:
{
"name": "proxy2a",
"author": "parker",
"version": "0.0.0-14",
"dependencies": {
},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
"node": "0.6.x",
"iisnode": "*"
},
"scripts": {
"start": "node proxy2a.js"
}
}
We have the code from this question. (Actually we need the server only to access one website, so it is fine that this server only serves one.)
This code works great when we run the server on our local machine.(Use node version 0.6.x.)
But when we deploy to appfog, there is no reaction. (We get the ip by pinging the deploy url with another console.) Do you know how to get such a proxy server to work on appfog or any other node.js host?
Your code works exactly as-is for me. I copied your two files as-is, and ran the following commands--
af login
// enter my creds
af update testproxy
Then went to http://testproxy.aws.af.cm/ and it works. Are you sure you uploading your app correctly, are using the correct domain name, and that your app is started?
(VCAP_APP_PORT is set to 80, so your app will be running on port 80 due to this line: var port = process.env.VCAP_APP_PORT || 8080;)