【发布时间】:2017-06-08 19:28:43
【问题描述】:
我正在使用带有 PouchDB 的 Angular 4 从 CouchDB 2.0 安装中获取数据。此外,我正在使用 pouchdb-authentication 插件进行登录和注册过程。
登录和注册过程运行良好。
couchdb 向我发送超时的唯一情况是,当我以角度 (/product/:id) 将路线从 /product/1 切换到 /product/2 两次时。 在每次路由更改时,我都会发送一个从 couchdb 获取会话的请求(可能不是很智能,但它应该仍然可以工作)但是在来回 couchdb 后,我会在 10 秒后向我发送超时。这次我也无法访问 couchdb 接口。 我尝试自己发送 http 请求,而不是使用插件,但这并没有解决问题。
这是我的身份验证服务:
export class AuthGuard implements CanActivate {
public UserDB;
constructor(
private router: Router,
public appState: AppState
) {
this.UserDB = new PouchDB(this.appState.get('couchdburl') +
'_users', {skipSetup: true});
}
public canActivate(route: ActivatedRouteSnapshot, state:
RouterStateSnapshot) {
return this.isLoggedIn();
}
public isLoggedIn() {
return this.UserDB.getSession().then((response) => {
if ( typeof response.userCtx !== typeof undefined && response.userCtx.name !== null ) {
return true;
} else {
this.router.navigate(['/login']);
return false;
}
}).catch((err) => {
console.log(err);
});
}
这些是我的路线:
export const ROUTES: Routes = [
{ path: '', component: LoginComponent, pathMatch: 'full' },
{ path: 'login', component: LoginComponent},
{ path: '', component: MainComponent, children: [
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'user-management', component: UserManagementComponent,
canActivate: [AuthGuard] },
{ path: 'product/:id', component: ProjectComponent,
canActivate: [AuthGuard] },
] },
{ path: '**', component: NoContentComponent },
];
【问题讨论】:
-
在github上提交了一个问题:github.com/pouchdb/pouchdb/issues/6556