how to set knex connection ssl options when using a connection string

邮差的信 提交于 2019-12-24 14:57:15

问题


How can I set my connection's ssl property to true when I'm using a connection string to initialize knex? Similarly how to set the debug to true? I would normally pass in a connection object but in this case I have to use a connection string from environment variables.

var database = {
    client: 'pg',
    connection: connstr //normally I would pass in the object below
    //connection: {
    //    "host": config.get('database_host'),
    //    "user": config.get('database_user'),
    //    "password": config.get('database_password'),
    //    "database": config.get('database_name'),
    //    "debug": config.get('database_debug'),
    //    "ssl":config.get('database_ssl')
    //}
};

var knex = require('knex')(database);
knex.connection.ssl = true;  // this doesn't seem to do anything

回答1:


Simply add ?ssl=true to the end of your connection string (at the end of the database name). For debug, either append ?debug=true after setting ssl or &debug=true I'm actually not sure sorry so just try both.



来源:https://stackoverflow.com/questions/30652809/how-to-set-knex-connection-ssl-options-when-using-a-connection-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!