I am trying to push my angular express web app to bluemix, but I am getting this error
2016-04-05T20:12:50.96-0300 [App/0] OUT > angular-expess-seed-
with-html#0.0.1 start /home/vcap/app
2016-04-05T20:12:50.96-0300 [App/0] OUT > node app.js
2016-04-05T20:12:51.19-0300 [App/0] OUT Express server listening
on port 3000 in production mode
2016-04-05T20:13:50.37-0300 [DEA/34] ERR Instance (index 0) failed
to start accepting connections
2016-04-05T20:13:50.39-0300 [API/2] OUT App instance exited with
guid b3554c4b-11f5-433f-891e-1df16605df80 payload:
{"cc_partition"=>"default", "droplet"=>"b3554c4b-11f5-433f-891e-
1df16605df80", "version"=>"36d8b569-d38a-465d-8bc6-b14ffd13b413",
"instance"=>"dbd3566e0ef348d9b9f483a32e8fed89", "index"=>0,
"reason"=>"CRASHED", "exit_status"=>-1, "exit_description"=>"failed to
accept connections within health check timeout",
"crash_timestamp"=>1459898030}
2016-04-05T20:13:50.40-0300 [App/0] ERR
2016-04-05T20:14:16.36-0300 [DEA/24] OUT Starting app instance
(index 0) with guid b3554c4b-11f5-433f-891e-1df16605df80
First it was complaining about the start script missing I've fixed that part but no such with this error.
I can see from the error below:
Express server listening
on port 3000 in production mode
that your Node.js application is trying to listen in port 3000. That works in local environment, but for Bluemix you have to get the port from the Cloud Foundry (CF) environment.
Here is a sample code to do that:
// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');
// get the app environment from Cloud Foundry
var appEnv = cfenv.getAppEnv();
// start server on the specified port and binding host
app.listen(appEnv.port, '0.0.0.0', function() {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
});
Related
I have my Java Spring backend deployed to GAE flexible environment. I'm using netty-socketio for hosting a socketIO server. I'm able to connect with socket.io-client using the public IP adress provided for the instance that is listed here:
And this is how I'm connecting to it:
const io = require("socket.io-client");
const socket = io("ws://<IP adress>:<PORT>", {
reconnectionDelayMax: 10000,
query: {
"deviceId": serial
}
});
socket.on("connect", () => {
console.log("Connected. Session ID: " + socket.id);
});
Please note that netty-socketio only supports version 1.0+ so I'm using socket.io-client 1.7.4 which is not the latest version.
I'm also using a custom domain. My problem is that I'm only able to connect to the server using the IP adress but when I'm using the domain name I'm having a timeout error:
socket.io-client:url parse ws://<DOMAIN>:<PORT> +0ms
socket.io-client new io instance for ws://<DOMAIN>:<PORT> +4ms
socket.io-client:manager readyState closed +3ms
socket.io-client:manager opening ws://<DOMAIN>:<PORT> +0ms
socket.io-client:manager connect attempt will timeout after 20000 +48ms
socket.io-client:manager readyState opening +6ms
socket.io-client:manager connect attempt timed out after 20000 +20s
socket.io-client:manager connect_error +2ms
socket.io-client:manager cleanup +1ms
Connect error: timeout
socket.io-client:manager will wait 868ms before reconnect attempt +2ms
socket.io-client:manager attempting reconnect +870ms
socket.io-client:manager readyState closed +0ms
socket.io-client:manager opening ws://<DOMAIN>:<PORT> +1ms
socket.io-client:manager connect attempt will timeout after 20000 +4ms
This is how I'd like to connect:
const io = require("socket.io-client");
const socket = io("ws://<DOMAIN>:<PORT>", {
reconnectionDelayMax: 10000,
query: {
"deviceId": serial
}
});
socket.on("connect", () => {
console.log("Connected. Session ID: " + socket.id);
});
The things I did to make it work so far:
I'm having a network session in the app.yaml with the following configuration:
network:
session_affinity: true
forwarded_ports:
- <PORT>/tcp
I made a firewall rule to allow connection on the port I'm trying to connect:
gcloud compute firewall-rules create default-allow-websockets --allow tcp:<PORT> --description "Allow websocket traffic"
I could use it like this of course but this IP constantly changes once I stop and restart the instance. Hope you got some tips for me!
Do you know if your hostname is resolving within your app? A lot of times services like this can use split DNS so there's a possibility that your code isn't resolving the same same public IP that you expect.
I'd recommend throwing together a quick test to see what your <DOMAIN> resolves to to ensure it's what you expect.
I'm trying to proxy outbound API calls made from a Google App Engine application via a Google Compute Engine server VM instance running Squid proxy server.
The aim is that the REST api calls will all be made from a static ip address so that the 3rd party API will be able to identify and permit the calls via their firewall.
I have read and followed the instructions on this post:
connect Google App Engine and Google Compute Engine
I have managed to do the following so far:
Created a Google cloud compute VM and successfully assigned it a static external IP address.
Created a Serverless VPC access connector successfully (all resources are located in the same GAE region).
Added the vpc_access_connector name to my app.yaml in the Google App Engine project (which runs on Node.js).
Deployed the app using gcloud beta, with api calls being targeted towards the internal IP address of the proxy server, using the correct Squid default port (3128).
On issuing a request from the GAE app, I can see from the server logs that the correct IP address and port are being attempted but get the following error: "Error: tunneling socket could not be established, cause=connect ECONNREFUSED [my-internal-ip-address]:3128"
I've also tried running a curl command from the cloud shell interface, but the request times out every time.
If anyone could help solve this issue, I will be very grateful.
Here is a possible example of how to proxy outbound HTTP requests from an App Engine Standard application on NodeJS runtime via a Compute Engine VM running Squid, based on a slight modification of the available Google Cloud Platform documentation 1 2 and Quickstarts 3.
1. Create a Serverless VPC Access conector: Basically follow 2 to create the connector. After updating the gcloud components and enabling the Serverless VPC Access API on your project running the following command should suffice:
gcloud compute networks vpc-access connectors create [CONNECTOR_NAME] \
--network [VPC_NETWORK] \
--region [REGION] \
--range [IP_RANGE]
2. Create a Compute Engine VM to use as proxy: Basically follow 1 to set up a Squid proxy server:
a. Reserve a static external IP address and assign it to a Compute Engine VM.
b. Add a Firewall rule to allow traffic on Squid's default port: 3128. This command should work if you are using the default VPC network: gcloud compute firewall-rules create [FIREWALL_RULE_NAME] --network default --allow tcp:3128
c. Install Squid on the VM with the following command sudo apt-get install squid3.
d. Enable the acl localnet src entries in the Squid config files for the VPC Access connector:
sudo sed -i 's:#\(http_access allow localnet\):\1:' /etc/squid/squid.conf
sudo sed -i 's:#\(acl localnet src [IP_RANGE]/28.*\):\1:' /etc/squid/squid.conf
For example: if you used 10.8.0.0 as value for the [IP_RANGE] field for creating the connector, it should look something like sudo sed -i 's:#\(acl localnet src 10.8.0.0/28.*\):\1:' /etc/squid/squid.conf
e. Start the server with sudo service squid start
3. Modifications on App Engine application: Based on the Quickstart for Node.js modify the following files in order to create an application that crawls a webpage using the request-promise library and displays the HTML of the webpage. The request is send to the webpage using the VPC Access connector and the VM as a proxy with the modifications of the app.yaml and app.js files.
a. package.json
...
"test": "mocha --exit test/*.test.js"
},
"dependencies": {
"express": "^4.16.3",
"request": "^2.88.0",
"request-promise": "^4.2.5"
},
"devDependencies": {
"mocha": "^7.0.0",
...
b. app.js
'use strict';
// [START gae_node_request_example]
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res
.status(200)
.send('Hello, world!')
.end();
});
//Add a handler to test the web crawler
app.get('/test', (req, res) => {
var request = require('request-promise');
request('http://www.input-your-awesome-website.com')
.then(function (htmlString) {
res.send(htmlString)
.end();
})
.catch(function (err) {
res.send("Crawling Failed...")
.end();
});
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
// [END gae_node_request_example]
c. app.yaml
runtime: nodejs10
vpc_access_connector:
name: "projects/[PROJECT]/locations/[REGION]/connectors/[CONNECTOR_NAME]"
env_variables:
HTTP_PROXY: "http://[Compute-Engine-IP-Address]:3128"
HTTPS_PROXY: "http://[Compute-Engine-IP-Address]:3128"
Each time you go to the /test handler monitor that the requests go through the proxy by using sudo tail -f /var/log/squid/access.log command from the VM and checking the changes on the logs.
Notes: The connector, application and VM need to be on the same region to work and these are the supported regions for the connector.
I'm trying to deploy a Jhipster application (Spring Boot + AngularJS) to Bluemix Tomcat. However I always get this error:
Error restarting application: Start app timeout
TIP: The application must be listening on the right port. Instead of hard coding the port, use the $PORT environment variable.
The complete error on Bluemix console is:
App instance exited with guid 1c76324f-57fb-4a00-b203-499519b4367c payload:
{
"cc_partition"=>"default",
"droplet"=>"1c76324f-57fb-4a00-b203-499519b4367c",
"version"=>"0103e173-b6d3-4daa-a291-b5792c16b69b",
"instance"=>"0c09506c30764b6c921cabb9a55d9e45",
"index"=>0,
"reason"=>"CRASHED",
"exit_status"=>255,
"exit_description"=>"failed to accept connections within health check timeout",
"crash_timestamp"=>1479341938
}
Instance (index 0) failed to start accepting connections
I've already tried to change the application-dev.yml config to
server:
port: ${VCAP_APP_PORT}
Or
server:
port: 80
However, I have not had any success. How can I pass the port variable to the Jhipster configuration?
you are my last chance here. So I've build a project with generator-sql-fullstack package and trying to deploy it to heroku.
Unfortunately, I can't connect to Heroku database as I get Error R10.
I've tried different ways to connect to postgres through sequelize - none of them worked. The main thing was to make it ssl compatible, but it still doesn't connect (or maybe I am using it wrong)
Project runs great locally, app is build without any errors also.
Please, take a look into Heroku logs and main files for connection. Hopefully, you will be able to help me here. Thank you.
$ heroku logs
2016-04-18T21:27:36.994697+00:00 app[web.1]: > node server/app.js
2016-04-18T21:27:36.994705+00:00 app[web.1]:
2016-04-18T21:27:37.784886+00:00 app[web.1]: Express server listening on 55648, in production mode
2016-04-18T21:28:34.891786+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-04-18T21:28:34.891786+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-04-18T21:28:35.750471+00:00 heroku[web.1]: Process exited with status 137
/server/config/environment/production.js
module.exports = {
database: 'DBNAME',
username: 'DBUSERNAME',
password: 'DBPASSWORD',
sql: {
host: 'DBHOST',
port: process.env.PORT || '5432',
dialect: 'postgres',
dialectOptions: {
ssl: true
}
}
};
/server/api/index.js
var sequelize = new Sequelize(config.database, config.username, config.password, config.sql);
Other than that, nothing was touched on server side.
My guess is that I am using Sequelize incorrectly, but I followed documentation (to adapt SSL for heroku).
Please, let me know if you want to see more configuration files.
Thank you for any input!
This:
var sequelize = new Sequelize(process.env.DATABASE_URL);
should be enough for connecting to Heroku's Postgres. You can check that DATABASE_URL in Heroku Dashboard -> YourApp -> Settings -> Config Variables. You can also take db credentials from that string, but you don't need to.
process.env.PORT is not the database port, but port on which you should start your server(so Heroku can do its internal routing things), like:
server.listen(process.env.PORT || 5432)
So you config file should look something like:
module.exports = {
port: process.env.PORT || 5432,
database: {
uri: process.env.DATABASE_URL
}
};
And connecting to database with:
var sequelize = new Sequelize(config.database.uri);
I'm running GAE dev server within a Vagrant guest precise64 box with the following network setup (in my Vagrantfile):
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network :forwarded_port, guest: 8080, host: 9090
end
Which does its thing:
[default] Forwarding ports...
[default] -- 8080 => 9090 (adapter 1)
I start my App Engine server with:
goapp serve
or
dev_appserver.py myappfolder
This starts app engine dev server as expected:
INFO 2013-11-22 dispatcher.py] Starting module running at: http://localhost:8080
In all cases, I'm able to ssh in to the Vagrant guest and curl localhost:8080 successfully.
Unfortunately, from the host I'm unable to get a response from localhost:9090 when running GAE dev web server. Additionally, I've made sure that I don't have anything interfering with the port 9090 on the host machine. Also, I'm almost positive this isn't related to Vagrant as I spun up a quick node.js web server on 8080 and was able to reach it from the host. What am I missing?!!!
You must run the Google App Engine Go dev web server on 0.0.0.0 when leveraging Vagrant port forwarding. Like so:
goapp serve -host=0.0.0.0
See the answers here for more info on ensuring the guest web server is not bound to 127.0.0.1 which is loopback. Web servers that bind to 127.0.0.1 (like App Engine Go dev web server does) by default should be overridden to use 0.0.0.0.