如何解决使用远程时,连接数据库的node-postgress很好,但是本地主机失败
背景:
我能够很好地连接到数据库,并且一切都可以在我的本地计算机上按预期工作,而我在本地计算机上(使用远程计算机的IP )远程连接到数据库。但是,当我将同一应用程序推送到该远程计算机,并将数据库URL的 public class DevClaimsTransformer : IClaimsTransformation
{
private static Dictionary<string,List<DevClaim>> devRoleClaims;
public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
{
if (devRoleClaims == null)
{
devRoleClaims =
JsonSerializer.Deserialize<Dictionary<string,List<DevClaim>>>(
File.ReadAllText("dev-claims.json"));
}
var identity = (ClaimsIdentity)(principal?.Identity ?? throw new ArgumentNullException(nameof(principal)));
if (identity.IsAuthenticated)
{
foreach (var rc in devRoleClaims)
{
foreach (var c in rc.Value)
{
if (c.Active)
{
identity.AddClaim(new Claim(rc.Key,c.Claim));
}
}
}
}
return new ClaimsPrincipal(identity);
}
private class DevClaim
{
public string Claim { get; set; }
public bool Active { get; set; }
}
}
变量更改为env
时,它将无法连接到数据库。>
它没有向我报告任何错误。任何查询pg池的尝试都将挂起,.query函数将永远不会返回任何信息,错误或其他原因。
这是我的代码:
server.js
localhost
routes / api.js
const apiRouter = require('./routes/api');
const { Pool } = require('pg');
/* ... */
//Postgres DB set up
let pool = new Pool(); // Connect vars are supplied by dot-env
/* ... */
// Catch all api requests
app.use('/api',apiRouter({ pool,transport }));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。