在loopback项目中连接DataSource时,遇到了一个很莫名的错误:
这是config代码:
const config = {
name: 'x',
connector: 'postgresql',
url: '',
host: '10.6x.xxx.xx',
port: 5432,
user: 'postgres',
password: 'xxxxxx',
database: 'postgres'
};
之前项目数据库配置都是这么写的,完全没出现这个问题,但是现在就是报这个‘url’ TypeError。
弄了半天终于找到了解决的办法,也是令我意想不到,它就是——注释掉这个url或者给它赋一个undefined值就可以了。
const config = {
name: 'x',
connector: 'postgresql',
//url: '',
host: '10.xx.xx.xx',
port: 5432,
user: 'postgres',
password: 'xxxxxxxx',
database: 'postgres'
};
const config = {
name: 'x',
connector: 'postgresql',
url: undefined,
host: '10.xx.xx.xxx',
port: 5432,
user: 'postgres',
password: 'xxxxxx',
database: 'postgres'
};
没有想通这个原理