我在域上有一个客户端应用程序,在域上client-domain.com有一个服务器端应用程序server-domain.com.服务器端有一个API.客户端应用程序将AJAX请求发送到服务器端应用程序.我使用基于令牌的身份验证,因此客户端应用程序在每个AJAX请求的头文件中发送令牌,例如:"授权:承载{某些令牌}".当我需要获取或发布一些数据时,它可以很好地处理AJAX请求.
但服务器端API也保留文件.例如图像.文件是私有的,只有经过身份验证的用户才能获取它们.我需要在<img>标签的客户端显示这些图像.我无法使用它们,<img src="http://server-domain.com/path/to/image">因为在这种情况下,浏览器不会向服务器端发送Authorization标头.
采用的解决方案是什么?客户端应用程序如何从服务器端API加载图像?
我想使用nodejs从https服务器下载文件.我试过这个功能,但它只适用于http:
var http = require('http');
var fs = require('fs');
var download = function(url, dest, cb) {
var file = fs.createWriteStream(dest);
var request = http.get(url, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb);
});
});
}
Run Code Online (Sandbox Code Playgroud) 我使用带有sw-toolbox库的服务工作者.我的PWA缓存除API查询(图像,css,js,html)之外的所有内容.但是如果某些文件有一天会被改变怎么办呢.或者如果将更改service-worker.js会怎样.应用程序应该如何知道文件的变化?
我的service-worker.js:
'use strict';
importScripts('./build/sw-toolbox.js');
self.toolbox.options.cache = {
name: 'ionic-cache'
};
// pre-cache our key assets
self.toolbox.precache(
[
'./build/main.js',
'./build/main.css',
'./build/polyfills.js',
'index.html',
'manifest.json'
]
);
// dynamically cache any other local assets
self.toolbox.router.any('/*', self.toolbox.cacheFirst);
// for any other requests go to the network, cache,
// and then only use that cached resource if your user goes offline
self.toolbox.router.default = self.toolbox.networkFirst;
Run Code Online (Sandbox Code Playgroud)
我不知道在PWA中更新缓存的常用方法是什么.也许PWA应该在后台发送AJAX请求并检查UI版本?
我有一个在构造函数中分派操作的组件:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
constructor(store: Store<State>) {
store.dispatch(action1());
store.dispatch(action2());
}
}
Run Code Online (Sandbox Code Playgroud)
我需要测试 action1 和 action2 是否已调度。我正在尝试使用 MockStore 来做到这一点:
import {MockStore, provideMockStore} from '@ngrx/store/testing';
let store: MockStore;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
AppComponent
],
providers: [
provideMockStore({ initialState }),
],
}).compileComponents();
store = TestBed.inject(MockStore);
});
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
it('should dispatch an action1 in constructor', () => {
TestBed.createComponent(AppComponent);
const expected = cold('a', {a: action1()});
expect(store.scannedActions$).toBeObservable(expected);
});
it('should dispatch an action2 in constructor', () …Run Code Online (Sandbox Code Playgroud) 我不明白在typescript应用程序中如何包含自定义类型定义文件.例如,这种应用有src/custom-typings.d.ts文件,其中包含自定义的类型定义.如何包含此文件?
我试图重命名这个文件,无论如何都包括在内.文件扩展名可以*.ts(不仅*.d.ts).webpack是否*.ts在项目的每个文件中搜索类型定义?如果是这样,那么如何改变这种行为呢?如何告诉webpack搜索特定文件中的类型定义?
我使用 AWS Lambda + Cognito(用户池 + 联合身份)+ API 网关。用户使用amazon-cognito-identity-js在 WEB 应用程序中进行身份验证,并使用aws-api-gateway-client调用 API 。API 网关方法具有 AWS_IAM 授权方。如何在 Lambda 函数中获取用户名(来自用户池)?
我在我的 Web 应用程序中使用 AWS IoT 进行实时更新。该应用程序使用aws-iot-device-sdk连接到 AWS IoT :
const client = awsIot.device({
region: awsConfig.region,
protocol: 'wss',
accessKeyId: <accessKey>,
secretKey: <secretKey>,
sessionToken: <sessionToken>,
port: 443,
host: <iotEndpoint>
});
client.on('connect', res => {
// ok
});
Run Code Online (Sandbox Code Playgroud)
我想使用 AWS生命周期事件。例如:
$aws/events/presence/connected/{clientId}
Run Code Online (Sandbox Code Playgroud)
如何获取 MQTT 客户端 ID?
我有一个指令:在模板中:
<territorial-selector></territorial-selector>
Run Code Online (Sandbox Code Playgroud)
在js中:
app.directive('territorialSelector', function() {
return {
restrict: 'E'
,templateUrl: 'partials/territorial-selector.html'
,controller: 'TerritorialSelectorController'
};
};
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该指令使用"TerritorialSelectorController"
在另一个地方,我有一个按钮,应该从TerritorialSelectorController执行方法loadTerritories().我创建了这个按钮:
<button ng-controller="TerritorialSelectorController" ng-click="loadTerritories()">BUTTON</button>
Run Code Online (Sandbox Code Playgroud)
在这种情况下TerritorialSelectorController创建两次的问题.这是TerritorialSelectorController的代码:
app.controller('TerritorialSelectorController', ['$scope', function($scope) {
alert('AAAAA'); // I have alert two times
}]);
Run Code Online (Sandbox Code Playgroud)
我只需要控制器的一个对象.
是否可以Settings => Editor => Code Style => Typescript从tslint.jsonwebstorm中的文件导入格式设置()?我"node_modules/codelyzer"在我的tslint.json文件中使用rules目录
angular ×3
javascript ×3
ajax ×1
angularjs ×1
api ×1
aws-cognito ×1
aws-iot ×1
aws-lambda ×1
https ×1
ionic3 ×1
ngrx ×1
ngrx-store ×1
node.js ×1
sw-toolbox ×1
tslint ×1
typescript ×1
webpack ×1
webstorm ×1