我有一个带有HttpInterceptor的核心模块用于授权处理,我在AppModule中包含了这个模块,这样使用HttpClient的所有其他模块都使用这个拦截器.
@NgModule({
imports: [],
declarations: [],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor,
multi: true,
},
]
})
export class CoreModule { }
Run Code Online (Sandbox Code Playgroud)
如何使模块绕过默认拦截器?
@NgModule({
imports: [
CommonModule
],
declarations: components,
providers: [CustomService],
exports: components,
})
export class ModuleWithoutInterceptorModule { }
Run Code Online (Sandbox Code Playgroud) 我有一个MongoDB,它存储了204.639.403项的产品数据,这些数据已经由项目的国家分散到同一个MongoDB进程中同一物理机器上运行的四个逻辑数据库中.
这是一个列表,其中包含每个逻辑数据库的文档数:
我的问题是数据库写入性能越来越差,特别是对四个数据库中最大的数据库(De)的写入变得非常糟糕,根据iotopmongod进程使用99%的IO时间,写入少于3MB,读取数据为1.5MB每秒.这导致长锁定数据库,100%+锁定通常根据mongostat- 即使所有进程写入和读取到其他国家/地区数据库已被停止.当前从站达到最大为6的LOAD,副本集主机同时具有2-3的负载,因此也导致复制滞后.
每个数据库都有相同的数据和索引结构,我使用最大的数据库(De)仅用于进一步的示例.
这是从数据库中取出的一个随机项,就像示例一样,该结构经过优化,只需一次读取即可收集所有重要数据:
{
"_id" : ObjectId("533b675dba0e381ecf4daa86"),
"ProductId" : "XGW1-E002F-DW",
"Title" : "Sample item",
"OfferNew" : {
"Count" : 7,
"LowestPrice" : 2631,
"OfferCondition" : "NEW"
},
"Country" : "de",
"ImageUrl" : "http://….jpg",
"OfferHistoryNew" : [
…
{
"Date" : ISODate("2014-06-01T23:22:10.940+02:00"),
"Value" : {
"Count" : 10,
"LowestPrice" : 2171,
"OfferCondition" : "NEW"
}
} …Run Code Online (Sandbox Code Playgroud) 在MongoDb文档3.2中,我看到它们支持3个存储引擎,MMAPV1,WiredTiger,In-Memory,这是一个非常令人困惑的选择.
我从描述中感受到了WiredTiger更好MMAPV1,但在其他来源中他们说MMAPV1更适合重读...而WiredTiger适合重写...
是否有一些限制何时选择一个而不是另一个?例如,有人可以提出一些最佳做法
当我有这种类型的应用程序通常是最好的,否则选择其他...
我陷入两难境地,尝试使用pre中间件向mongoose模型添加一些预逻辑,并且不能this像往常一样访问实例.
UserSchema.pre('save', next => {
console.log(this); // logs out empty object {}
let hash = crypto.createHash('sha256');
let password = this.password;
console.log("Hashing password, " + password);
hash.update(password);
this.password = hash.digest('hex');
next();
});
Run Code Online (Sandbox Code Playgroud)
问题:*有没有办法访问this实例?
我有以下拦截器:
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor(private tokenService: TokenService) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const token = this.tokenService.getToken();
if (token) {
const authReq = req.clone({
headers: req.headers.set('Authorization', `Bearer ${token}`)
});
return next.handle(authReq);
}
return next
.handle(req)
//
.getSomehowTheResponse()
.andSaveTheTokenInStorage()
.andPropagateNextTheResponse()
}
}
Run Code Online (Sandbox Code Playgroud)
我想从本地存储中的响应头保存令牌,所有教程都显示如何拦截请求,但不是很清楚响应.
我正在使用PapaPase解析大 CSV 文件,使用块模式。
我正在验证 csv 数据,我想在验证失败时停止流式传输。
但是经过一些解析后,我无法停止流式传输。
我试图停止使用块回调中的 return false ,但它不起作用。
下面是代码。
$("#fileselect").on("change", function(e){
if (this.files.length) {
var file = this.files[0]
count = 0;
Papa.parse(file, {
worker: true,
delimiter: "~~",
skipEmptyLines:true,
chunk: function (result) {
count += result.data.length;
console.clear();
console.log(count);
if (count>60000) {
return false;
}
},
complete: function (result, file) {
console.log(result)
}
});
}
});
Run Code Online (Sandbox Code Playgroud) 我有一个feathers.js 服务,我需要在使用post 时重定向到特定页面
class Payment {
// ..
create(data, params) {
// do some logic
// redirect to an other page with 301|302
return res.redirect('http://some-page.com');
}
}
Run Code Online (Sandbox Code Playgroud)
是否可以从feathers.js 服务重定向?