Aurelia服务器侧视图:将auth标头添加到view/viewmodel的http下载请求中 [英] Aurelia server side views: Adding auth header to http download request of view/viewmodel
问题描述
我正在使用示例Aurelia骨架项目(skeleton-esnext-aspnetcore),其C#/MVC后端来自:
I'm using the sample Aurelia skeleton project (skeleton-esnext-aspnetcore), with a C#/MVC backend from: https://github.com/aurelia/skeleton-navigation/tree/master/skeleton-esnext-aspnetcore
为了支持服务器侧视图,我更新了main.js中的视图定位器原型(ViewLocator.prototype.convertOriginToViewUrl),以从服务器请求视图/视图模型文件.此处的详细信息: http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/app-configuration-and-startup/9
To support server side views, I updated the view locator prototype (ViewLocator.prototype.convertOriginToViewUrl) in main.js to request the view/viewmodel files from the server. Details here: http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/app-configuration-and-startup/9
这可以正常工作,并且systemJS已成功从服务器下载/加载了示例视图/视图模型.
This works fine, and a sample view/viewmodel are successfully downloaded/loaded from the server by systemJS.
我想向http view/viewmodel请求中添加自定义auth标头,以标识后端的用户.我将如何在Aurelia中进行配置?
我有一个使用带有拦截器的Aurelia提取客户端的现有服务,该服务会将auth标头发送到API.我曾尝试在app/main.js中初始化获取客户端配置,但似乎无法解决问题.谢谢!
I have an existing service using the Aurelia fetch client w/interceptors, that is sending the auth headers to the API. I tried initializing the fetch client config earlier in the app/main.js, but it didn't appear to resolve the issue. Thanks!
推荐答案
I found a reference to the SystemJS configuration API: https://github.com/systemjs/systemjs/blob/master/docs/config-api.md
作为快速测试,我将以下代码添加到index.html中的现有脚本块中:
As a quick test, I added the following code to the existing script block in index.html:
<script>
System.config({
meta: {
'*': {
'authorization': 'bearer 123'
}
}
});
System.import('aurelia-bootstrapper');
</script>
在验证之后,添加了标题,我能够确认代码可以移入普通类,例如main.js:
After verifying, the header was added, I was able to confirm that the code can be moved into a normal class, like main.js:
System.config({
meta: {
'*': {
'authorization': 'bearer 123456'
}
}
});
这篇关于Aurelia服务器侧视图:将auth标头添加到view/viewmodel的http下载请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!