Postgres connection with SSL

Stimulsoft Reports.JS discussion
Post Reply
rafael_at
Posts: 5
Joined: Sun May 03, 2020 9:40 am

Postgres connection with SSL

Post by rafael_at »

Hi,

I’m currently evaluating Stimulsoft Reports.JS and .WEB, as we are considering to make a switch from SSRS and Tableau.

First problem I encounter is how to connect to our Postgres database with SSL. In the connection string in the macOS Designer I try “sslmode=require” “=true”, “ssl=true” etc. but nothing seems to work as the connection gets rejected with message that SSL is off. As far as I understand the macOS designer is based on the JS engine, i.e. it should be the same as Reports.JS. Does it use node-postgres package for Postgres connections?

Also where do I find a documentation about the connection string syntax used in Reports.JS and Reports.WEB?

Thanks
Rafael
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Postgres connection with SSL

Post by HighAley »

Hello, Rafael.

In Reports.JS there are 4 types of data adapters are available.
- node.js
- PHP
- ASP.NET
- Java

All of them are open source. You could select any of them and make necessary changes if you need.

On the side of JS report engine you should add just one line of code
https://www.stimulsoft.com/en/documenta ... _bases.htm

Code: Select all

StiOptions.WebServer.url = "http://example.com/data/handler.php";
Thank you.
rafael_at
Posts: 5
Joined: Sun May 03, 2020 9:40 am

Re: Postgres connection with SSL

Post by rafael_at »

Thanks for the info!
However, it doesn't really help, as I want to be able to use the macOS Designer.app. Only way I could solve this, was to actually hack your reports.js source code, which is embedded in the app bundle. I would suggest you add the option for SSL into the Posgres data adapter, as it would benefit reports.js in general AND the mac Designer.app. Another approach would be to allow defining the connection sring using the "postgres://..." notation, that's the hack I used, one line of code ;) I am sure, we are not the only (not yet) customers which need SSL to connect!
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Postgres connection with SSL

Post by HighAley »

Hello.

Could you sned us the change that you did in our code?
We will add them to the next build.

Thank you.
rafael_at
Posts: 5
Joined: Sun May 03, 2020 9:40 am

Re: Postgres connection with SSL

Post by rafael_at »

The change in:
https://github.com/stimulsoft/Samples-J ... er.js#L114
is more or less:

Code: Select all

var pg = require('pg');
if (command.connectionString.startsWith("postgres://")) command.postgreConnectionString = command.connectionString
else {
	//same as before:
	command.connectionStringInfo = getConnectionStringInfo(command.connectionString);

	command.postgreConnectionString = "postgres://" + command.connectionStringInfo.userId + ":" + command.connectionStringInfo.password + "@" + command.connectionStringInfo.host;
        if (command.connectionStringInfo.port != null) command.postgreConnectionString += ":" + command.connectionStringInfo.port;
        command.postgreConnectionString += "/" + command.connectionStringInfo.database;
}
var client = new pg.Client(command.postgreConnectionString);

connect();
This allows to use a connections string with parameters like: "postgres://user:pw@host:port/database?ssl=1". Alternatively you could add the property "SSL" to getConnectionStringInfo/command.connectionStringInfo.ssl and construct the connection string with the "?ssl=1" parameter.

cheers
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Postgres connection with SSL

Post by Lech Kulikowski »

Hello,

Thank you for the information. We have added these changes.
Post Reply