我正在尝试为我的angular2应用添加基本身份验证.
public login() {
// Set basic auth headers
this.defaultHeaders.set('Authorization', 'Basic ' + btoa(this.username + ':' + this.password));
console.log('username', this.username)
console.log('password', this.password)
console.log(this.defaultHeaders)
// rest is copy paste from monbanquetapiservice
const path = this.basePath + '/api/v1/development/order';
let req = this.http.get(path, { headers: this.defaultHeaders });
req.subscribe(
_ => { },
err => this.onError(err)
);
}
Run Code Online (Sandbox Code Playgroud)
我期望看到的是带有Authorization我放置的标题的GET请求.
但我看到的首先是带有此标题的OPTIONS:
OPTIONS /api/v1/development/order HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: http://localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X …Run Code Online (Sandbox Code Playgroud) const f = (arg1) => (arg2) => { /* returns something */ }
Run Code Online (Sandbox Code Playgroud)
关于2个参数是否可以记忆f,即:
f(1)(2);
f(1)(3); // Cache not hit
f(4)(2); // Cache not hit
f(1)(2); // Cache hit
Run Code Online (Sandbox Code Playgroud) 使用时Object.keys(obj),返回值为a string[],而我想要一个(keyof obj)[]。
const v = {
a: 1,
b: 2
}
Object.keys(v).reduce((accumulator, current) => {
accumulator.push(v[current]);
return accumulator;
}, []);
Run Code Online (Sandbox Code Playgroud)
我有错误:
元素隐式地具有“ any”类型,因为类型为“ {{a:number; b:数字;}'没有索引签名。
带有TypeScript 3.1 strict: true。游乐场:在这里,请选中所有复选框以Options将其激活strict: true。
我试图弄清楚如何使用Angular2路由器导航(路由器3.0.0-alpha.7)与查询参数.
我可以使用此行轻松导航到带有queryParam的路径:
this._router.navigate(['/login'], {queryParams: {redirect: 'route1'}});
Run Code Online (Sandbox Code Playgroud)
在'/ login'组件中,我做了一些登录,它将重定向到redirect路由,即route1.但是,重定向后,redirect查询参数保留在URL中,即我现在在页面/route1?redirect=route1.我想在这里删除重定向参数.
此外,如果我然后导航到具有相同redirectqueryParam的另一个页面,它不会覆盖前一个页面,但会?redirect=...在URL中添加另一个页面.即:
this._router.navigate(['/another-route'], {queryParams: {redirect:'route2'}});
Run Code Online (Sandbox Code Playgroud)
引导我 /another-route?redirect=route2?redirect=route1
在路由之间导航时是否可以清除queryParams?我试过this._router.navigate(['/route1'], {queryParams: {redirect: null}});,{queryParams: null}等等但没有成功.
我是jspm的新手,只从npm转换.我有一个基本问题.我在package.json中有一些依赖项,我运行了jspm init,它创建了一个很好的jspm config.js文件.我的问题是,从jspm(via jspm install ...)安装这些软件包的重点是什么?为什么不通过npm安装它们?
更具体地说,在我的package.json中,将这些包放在里面有什么区别 dependencies: {} vs inside jspm.dependencies: {}
是否可以在React Navigation的标题标题中访问整个Redux状态?
在官方的文档说,对应导航状态是可访问:
static navigationOptions = {
title: ({ state }) => `Chat with ${state.params.user}`
};
Run Code Online (Sandbox Code Playgroud)
但我希望访问我的Redux状态的其他部分,当状态更新时标题更新.今天有可能吗?
我从React Native开始,在iOS模拟器中一切正常.我决定在设备上试一试.
该应用程序启动,我可以玩它,我关闭/重新打开它大约4或5次,然后有点随机的应用程序崩溃在启动屏幕(具有"由本机反应").它只显示屏幕,应用程序崩溃到iPhone主屏幕.
知道如何进一步调试吗?
编辑:我在我的AppDelegate.m中添加了Bugsnag,但是当应用程序崩溃时,bugsnag没有检测到任何内容.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
[BugsnagReactNative start];
// Rest of code
}
Run Code Online (Sandbox Code Playgroud) 这是我的设置:
步骤 1. 使用以下代码创建一个 preload.js 文件:
window.ipcRenderer = require('electron').ipcRenderer;
Run Code Online (Sandbox Code Playgroud)
步骤 2. 通过 webPreferences 在 main.js 中预加载此文件:
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
preload: __dirname + '/preload.js'
}
});
Run Code Online (Sandbox Code Playgroud)
步骤 3. 在渲染器中:
console.log(window.ipcRenderer); // Works!
Run Code Online (Sandbox Code Playgroud)
现在按照 Electron 的安全指南,我想转contextIsolation=true:https : //electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content
步骤 2 之二。
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: __dirname + '/preload.js'
}
});
Run Code Online (Sandbox Code Playgroud)
第 3 步之二。在渲染器中:
console.log(window.ipcRenderer); // undefined
问题:我可以在什么时候使用ipcRenderercontextIsolation=true …
我使用Auth0来托管我的所有用户数据.我也有自己的后端,我希望有一个Users表,它将我的数据库生成映射userId到Auth0 user_id.注册时,我在两个流程之间犹豫不决:
user_id.POST /users(公共端点)以创建新用户user_id.user_id,因此db在user_id和我之间进行查找userId.POST /users我的后端.此调用将生成我的数据库userId并将其发送回Auth0.userId放到Auth0中user_metadata.user_metadata将包含在JWT中,因此对我的后端获取资源的所有调用都将包含db userId(不需要额外的查找).我觉得2更坚固.还有其他注册流程吗?一些auth0客户是否使用与我的#2类似的流程?我在他们的文档中找不到多少.
我正在使用官方的反应导航来处理我的导航.我有一个主要的TabNavigator用于整个应用程序,有两个选项卡(称为HitchhikingMapNavigator和SettingsNavigator下面),每个选项卡都有一个嵌套的StackNavigator:
const HitchhikingMapNavigator = StackNavigator({
hitchhikingMap: { screen: HitchhikingMapViewContainer },
spotDetails: { screen: SpotDetailsViewContainer }
}, {
navigationOptions: {
header: {
visible: false
}
}
});
const SettingsNavigator = StackNavigator({
// some other routes
});
export default AppNavigator = TabNavigator({
hitchhikingMap: { screen: HitchhikingMapNavigator },
settings: { screen: SettingsNavigator }
}, {
navigationOptions: {
header: {
visible: false,
},
},
});
Run Code Online (Sandbox Code Playgroud)
正如你所看到的那样,即使在我看来,我也把标题的可见性放在了虚假的地方HitchhikingMapViewContainer:
class HitchhikingMapView extends React.Component {
static navigationOptions = {
title: …Run Code Online (Sandbox Code Playgroud) react-native ×3
angular ×2
javascript ×2
auth0 ×1
caching ×1
cors ×1
crash ×1
currying ×1
electron ×1
http ×1
ios ×1
jspm ×1
memoization ×1
npm ×1
redux ×1
security ×1
typescript ×1