Connection refused on heroku using generator-sql-fullstack - angularjs

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);

Related

Connect a dockerized app to a database from a remote machine via a VPN connection

I'm currently working on a small app that has to fetch data from a SQL Server DB and push it on the cloud. It works correctly, but I would like to dockerize it to make its deployment easier.
The database is on a private network and I have to use a VPN connection to access it for development (in red in the diagram below). In production, the app will be on a VM in the database's network.
I'm still confused with Docker networks and the --publish option.
Here is my docker-compose file for now.
version: "3.4"
services:
myapp:
build:
context: .
network: host
restart: always
ports:
- "128.1.X.Y:1433:1433"
container_name: myapp
But when I connect to the VPN from my machine (remote) and run my image with this configuration, I get this error:
driver failed programming external connectivity on endpoint myapp (bbb3cc...):
Error starting userland proxy: listen tcp4 128.1.X.Y:1433: bind: cannot assign requested address
Simply "1433:1433" does not work either. The database cannot be accessed. Not really sure about "network: host" either...
Does anyone know what I could be doing wrong?
And another thing I'm wondering is, will the Docker config be the same when I will deploy my container on the VM?
Thank you!

Problem during deploying Metabase with Google App Engine

I am following this instructions for deploying metabase with Google App Engine, after I complete the operations and open the url where the service is deployed i get 502 Bad Gateway or
Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds. and from console I got
INFO metabase.driver :: Registered abstract driver :sql ?
This is my app.yaml
env: flex
manual_scaling:
instances: 1
env_variables:
MB_JETTY_PORT: 8080
MB_DB_TYPE: postgres
MB_DB_DBNAME: metabase
MB_DB_PORT: 5432
MB_DB_USER: devops
MB_DB_PASS: password
MB_DB_HOST: 127.0.0.1
beta_settings:
cloud_sql_instances: <instance-name>=tcp:5432
Dockerfile:
FROM gcr.io/google-appengine/openjdk
EXPOSE 8080
ENV PORT 8080
ENV MB_PORT 8080
ENV MB_JETTY_PORT 8080
ENV MB_DB_PORT 5432
ENV METABASE_SQL_INSTANCE <instance_name>=tcp:5432
ENV JAVA_OPTS "-XX:+IgnoreUnrecognizedVMOptions -Dfile.encoding=UTF-8 --add-opens=java.base/java.net=ALL-UNNAMED --add-modules=java.xml.bind"
ADD https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 ./cloud_sql_proxy
ADD http://downloads.metabase.com/v0.33.2/metabase.jar /metabase.jar
RUN chmod +x ./cloud_sql_proxy
CMD ./cloud_sql_proxy -instances=$METABASE_SQL_INSTANCE=tcp:$MB_DB_PORT & java -jar ./metabase.jar
Also I troubleshoot everything I saw on stackoverflow and tried all options with similar problem but still not working, i tried this option 1 and this options 2 but still no working effects.
My steps:
On GCP I am the owner of the project,I created Compute engine VM instance, then SQL Postgres instance, and a new Postgres database with user, I added the public IP address of the VM in the configurations of the SQL Instance as authorized network, and deployed the app.yaml and Dockerfile with gcloud app deploy. Any working solutons?
[1]: https://www.cloudbooklet.com/install-metabase-on-google-cloud-with-docker-app-engine/
I fixed the issue. I just change the metabase version, it always has to be the newest. 0.36.6 at this moment

React + Express on Azure: Invalid Host Header

The Error
When deploying to Azure Web Apps with Multi-container support, I receive an "Invalid Host Header" message from https://mysite.azurewebsites.com
Local Setup
This runs fine.
I have two Docker containers: client a React app and server an Express app hosting my API. I am using a proxy to host my API on server.
In client's package.json I have defined:
"proxy": "http://localhost:3001"
I use the following docker compose file to build locally.
version: '2.1'
services:
server:
build: ./server
expose:
- ${APP_SERVER_PORT}
environment:
API_HOST: ${API_HOST}
APP_SERVER_PORT: ${APP_SERVER_PORT}
ports:
- ${APP_SERVER_PORT}:${APP_SERVER_PORT}
volumes:
- ./server/src:/app/project-server/src
command: npm start
client:
build: ./client
environment:
- REACT_APP_PORT=${REACT_APP_PORT}
expose:
- ${REACT_APP_PORT}
ports:
- ${REACT_APP_PORT}:${REACT_APP_PORT}
volumes:
- ./client/src:/app/project-client/src
- ./client/public:/app/project-client/public
links:
- server
command: npm start
Everything runs fine.
On Azure
When deploying to Azure I have the following. client and server images have been stored in Azure Container Registry. They appear to load just fine from the logs.
In my App Service > Container Settings I am loading the images from Azure Container Registry (ACR) and I'm using the following configuration (Docker compose) file.
version: '2.1'
services:
client:
image: <clientimage>.azurecr.io/clientimage:v1
build: ./client
expose:
- 3000
ports:
- 3000:3000
command: npm start
server:
image: <serverimage>.azurecr.io/<serverimage>:v1
build: ./server
expose:
- 3001
ports:
- 3001:3001
command: npm start
I have also defined in Application Settings:
WEBSITES_PORT to be 3000.
This results in the error on my site "Invalid Host Header"
Things I've tried
• Serving the app from the static folder in server. This works in that it serves the app, but it messes up my authentication. I need to be able to serve the static portion from client's App.js and have that talk to my Express API for database calls and authentication.
• In my docker-compose file binding the front end to:
ports:
- 3000:80
• A few other port combinations but no luck.
Also, I think this has something to do with the proxy in client's package.json based on this repo
Any help would be greatly appreciated!
Update
It is the proxy setting.
This somewhat solves it. By removing "proxy": "http://localhost:3001" I am able to load the website, but the suggested answer in the problem does not work for me. i.e. I am now unable to access my API.
Never used azure before and I also don't use a proxy (due to its random connection issues), but if your application is basically running express, you can utilize cors. (As a side note, it's more common to run your express server on 5000 than 3001.)
I first set up an env/config.js folder and file like so:
module.exports = {
development: {
database: 'mongodb://localhost/boilerplate-dev-db',
port: 5000,
portal: 'http://localhost:3000',
},
production: {
database: 'mongodb://localhost/boilerplate-prod-db',
port: 5000,
portal: 'http://example.com',
},
staging: {
database: 'mongodb://localhost/boilerplate-staging-db',
port: 5000,
portal: 'http://localhost:3000',
}
};
Then, depending on the environment, I can implement cors where I'm defining express middleware:
const cors = require('cors');
const config = require('./path/to/env/config.js');
const env = process.env.NODE_ENV;
app.use(
cors({
credentials: true,
origin: config[env].portal,
}),
);
Please note the portal and the AJAX requests MUST have matching host names. For example, if my application is hosted on http://example.com, my front-end API requests must be making requests to http://example.com/api/ (not http://localhost:3000/api/ -- click here to see how I implement it for my website), and the portal env must match the host name http://example.com. This set up is flexible and necessary when running multiple environments.
Or if you're using the create-react-app, then simply eject your app and implement a proxy inside the webpack production configuration.
Or migrate your application to my fullstack boilerplate, which implements the cors example above.
So, I ended up having to move off of containers and serve the React app up in more of a typical MERN architecture with the Express server hosting the React app from the static build folder. I set up some routes with PassportJS to handle my authentication.
Not my preferred solution, I would have preferred to use containers, but this works. Hope this points someone out there in the right direction!

Bluemix Spring - Application must be listening on the right port

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?

Pushing app to bluemix

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);
});

Resources