我正在使用带有PouchDB的Angular 4来从CouchDB 2.0安装中获取数据。此外,我使用pouchdb-authentication插件进行登录和注册过程。
登录和注册过程运行正常。
couchdb发送超时的唯一事情就是我将来自/ product / 1的angular(/ product /:id)路由来回切换两次/ product / 2。 在每个路由更改我发送一个请求从couchdb获取会话(可能不是很聪明,但它应该仍然有效)但来回来后,couchdb在10秒后发送超时。在这段时间我也无法访问couchdb界面。 我尝试自己发送http请求而不是使用插件但是没有修复它。
这是我的Auth服务:
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 },
];
答案 0 :(得分:0)
如果您正在使用PouchDB实时sync
API来同步本地和远程数据库,则可能是您忘记取消用户注销时的实时同步。您可以查看here以查看其实施方式。
如果您未使用实时同步,问题可能是由于PouchDB allDocs()
选项。只需将timeout
选项设置为0
即可,看看它是否可以解决问题。