我正在开发一个 nodejs 项目,它在 GitHub 中有多个私有依赖项package.json,如下所示:
"dependencies" : {
"mymodule":"git+https://<token>:xoauthbasic@github.com/my_github_account/my_repo.git#<commit-ish>"
}
Run Code Online (Sandbox Code Playgroud)
我在这里有两个问题:
package.json为了安全起见,我不希望将 oAuth 令牌与我的文件分开。这些问题有什么解决办法吗?此外,如果解决方案适用于 Heroku,那就太好了。
我有一个Editor看起来像这样的组件:
class EditorComp extends Component {
focus() {
this.refs.input.focus();
}
render() {
return (
<input
ref="input"
...
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
因此,使用的元素EditorComp可以设置ref并调用其focus方法并将焦点应用于较低级别的输入,如下所示:
class Parent extends Component {
render() {
return (
<div>
<button onClick={() => this.refs.editor.focus()}>Focus</button>
<EditorComp ref="editor" />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
然而,当包装EditorComp在高阶组件(如react-reduxs connect())中时,EditorComp失去焦点方法,因为它被困在HOC下面.
例:
const WrappedEditor = connect()(EditorComp); // react-redux's connect, for example
const wrappedEditorInstance = <WrappedEditor />;
wrappedEditorInstance.focus() // Error! Focus is not a …Run Code Online (Sandbox Code Playgroud) 有没有办法在快速中间件中获取请求的套接字?
IE:
import express from 'express';
import io from 'socket.io';
const app = express();
// combine app and io somehow ...
// When client makes a GET request to '/emit/to/self', that client's socket will recieve the 'hello:world' message.
app.get('/emit/to/self', (req, res) => {
req.socket.emit('hello:world', { ... });
res.send('You just triggered your own socket!')
})
Run Code Online (Sandbox Code Playgroud)
这个想法是 express 中间件具有req.socket引用来自同一客户端的连接套接字的属性。这将允许一些更复杂的用例,例如:
app.post('/image/create', (req, res) => {
createExpensiveImage({
onProgress: (progress) => { req.socket.emit('image:progress', { progress }) },
});
})
Run Code Online (Sandbox Code Playgroud)
客户端将拥有他们刚刚请求通过 API 创建的图像的准确进度条。