我有一个与阿波罗客户端的应用程序。当用户登录时,我可以查询客户端状态并检索用户,但是,当我刷新页面时,不再设置用户数据。
如您所见,我在我的index.js文件中设置了客户端,然后将其传递给ApolloProvider包装了整个应用程序的文件。
// index.js
const client = () => {
const cache = new InMemoryCache()
persistCache({
cache,
storage: window.localStorage
})
return new ApolloClient({
uri: graphQLUri,
credentials: 'include',
clientState: {
defaults: {
locale: "en-GB",
user: {
__typename: "User",
isLoggedIn: false,
username: "",
salesChannel: "",
fullName: ""
}
},
typeDefs: `
enum Locale {
en-GB
fr-FR
nl-NL
}
type Query {
locale: Locale
}
`
},
cache
})
}
ReactDOM.render(
<ApolloProvider client={client()}>
<App />
</ApolloProvider>,
document.getElementById("root") …Run Code Online (Sandbox Code Playgroud) 我想根据用户输入的子域进行重定向.
例如:
<subdomain>.example.com/admin -> <subdomain>.myurl.com
理想情况下,我想将<subdomain>参数作为参数传递给我的重定向网址.
我正在寻找与此类似的东西:
location ~ (sub).(somewhere).(com)/(some)(thing)/(something)(else) {
set $var1 = $1; # = sub in above example
set $var2 = $2; # = somewhere in above example
set $var3 = $3; # = com in above example
set $var4 = $4; # = some in above example
set $var5 = $5; # = thing in above example
set $var6 = $6; # = something in above example
set $var7 = $7; # = else …Run Code Online (Sandbox Code Playgroud) 我试图创建一个代表用户的类,我希望它继承猫鼬类的方法,该类具有查找,保存,删除等功能。
我试图通过实质上执行以下操作来扩展猫鼬模型: class User extends Mongoose.model('User', UserSchema) {}
我的实际代码如下所示:
import { Mongoose } from '../config';
const Schema = Mongoose.Schema;
const UserSchema = new Schema({
email: { type: String, default: '' },
firstName: { type: String, default: '' },
lastName: { type: String, default: '' },
facebookId: { type: String, default: '' },
payments: { type: Array, default: [] }
});
const MongoUser = Mongoose.model('User', UserSchema);
class User extends MongoUser {
constructor(data) {
super();
this.email;
this.firstName;
this.lastName;
this.facebookId;
this.payments;
}
save(){ …Run Code Online (Sandbox Code Playgroud) 我想在用户到达页面上的某个点时更新window.location.hash值.
例如,如果用户滚动到ID ='about'的div,我想要更新url.
与单击自动滚动到页面上的锚点的链接的方式相同,它会更新URL中的哈希值.
我设想通过检测元素是否可见来实现这一点,如果是,则更新window.location.hash = elementsID
打开其他建议.
我正在使用React并试图避免使用JQuery,因此非常感谢vanilla的JS建议.谢谢.
编辑:
谢谢你的建议.管理以与vanilla JS组合解决方案并在react组件中实现它.代码仍然需要清理,但你得到了要点
class HomeView extends React.Component{
constructor () {
super();
this.state = {
hash: '#'
}
this.elements = {}
}
componentDidMount(){
this.scrollListener();
}
componentDidUpdate(prevProps){
if(this.props.location.hash !== prevProps.location.hash){
this.scrollToHash(this.props.location.hash)
}
}
scrollListener(){
window.addEventListener('scroll', (event) => {
if(window.pageYOffset > 0 && window.pageYOffset < this.elements.about.offsetTop - 200){
const hash = '#';
this.setState({hash: hash}, () => {
history.pushState('', '', hash);
this.updateHashState(hash);
})
} else if(window.pageYOffset > this.elements.about.offsetTop - 200 && window.pageYOffset < this.elements.skills.offsetTop - …Run Code Online (Sandbox Code Playgroud) 我有一个部署脚本,我只想在测试成功时运行,但我相信我的条件语句有问题if [ "$VALID" ]
#!/bin/bash\n\n# install dependencies\necho \'INSTALLING YARN\'\nnpm install yarn -g\n\necho "INSTALLING DEPENDENCIES"\nyarn install\n\necho "TESTING"\nVALID="$(npm test)"\n\nif [ "$VALID" ]\n then \n\n # ZIP up the code\n echo \'INSTALLING ZIP\'\n apt-get update\n echo "y" | apt-get install zip\n\n echo \'ZIPPING\'\n zip -r ./Lambda-Image-Compression.zip index.js node_modules\n\n # install aws cli so we can deploy code\n echo \'INSTALLING PIP\'\n # echo "y" | apt-get install python-pip\n echo "y" | apt-get install python-pip python-dev build-essential \n echo "y" | pip install …Run Code Online (Sandbox Code Playgroud) 尝试从我在 Google Cloud App Engine 上运行的 Node 应用程序连接到 Atlas mongodb 实例并收到以下错误:
MongoError: no mongos proxy available at Timeout
我的连接字符串基本上是这样的:(出于明显的原因,已经稍微更改了一些分片的名称)
mongodb://
<username>:<password>@
shard-00-00-hfnfz.gcp.mongodb.net:27017,
shard-00-01-hfnfz.gcp.mongodb.net:27017,
shard-00-02-hfnfz.gcp.mongodb.net:27017
/test
?ssl=true
&replicaSet=shard-0
&authSource=admin
Run Code Online (Sandbox Code Playgroud)
我可以使用 Compass 从本地连接正常。但是,当尝试通过我在 Google Cloud App Engine 中运行的应用程序进行连接时,我的日志中出现了上述错误。
我正在从节点中的远程文件创建GIF,目前通过将每个图像下载到文件系统到tmp文件夹.
我想绕过将图像保存到tmp文件夹并保存在内存中.这可能吗?
如您所见,我的AWS类中有一个下载函数,它保存到tmp文件夹:
download(key){
return new Promise((resolve, reject) => {
request.head(`${this.base_url}/${this.bucket}/${key}`, (err, res, body) => {
request(`${this.base_url}/${this.bucket}/${key}`)
.pipe(fs.createWriteStream(`tmp/${key}`)).on('close', resolve )
})
})
};
Run Code Online (Sandbox Code Playgroud)
一旦他们全部下载了,我在我的GifService类中有一个createGif函数,它将每个文件路径添加为自定义参数gm,添加50ms的延迟,然后调整输出作为缓冲区,然后我上传到AWS s3.
import gm from 'gm';
...
constructor(){
this.gm = gm()
}
generateGif(images, prefix){
return new Promise((resolve, reject) => {
// for each image we want in array, we pass to gm
images.forEach(image => {
this.gm.in(`tmp/${image.Key}`)
})
// Now we create the gif with 50sec delay between images, sized to 600px x 2
this.gm
.delay(50) …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据条目的名称自定义字段检索单个条目。
我尝试过使用 JS SDK 和各种选项:
client.getEntry("entryID")
// .where("content_type", "Restaurant")
// .where("fields.name[match]", "RestaurantName")
// .all()
.then(data => console.log('data', data))
.catch(err => console.log('err', err))
Run Code Online (Sandbox Code Playgroud)
但根据返回的错误,这表明我只能使用.getEntry并传入条目 ID。
我还考虑过使用 发出 HTTP 请求,axios但遇到了类似的问题,只能检索完整的条目列表或根据条目 ID 进行过滤。
我可以通过 `field.name === "Slug" 或我添加的其他自定义字段来获取吗?
我正在使用以下代码创建链接 URL:
Linking.makeUrl('lobby/', {
roomId: params.roomId
})
Run Code Online (Sandbox Code Playgroud)
输出以下内容: exp://192.168.0.31:19000/--/lobby/?roomId=1585512451
这在本地工作正常,但似乎只能打开我的应用程序的主页。
我已经在我的 app.js 中定义了屏幕
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
/>
<Stack.Screen
name="Lobby"
component={LobbyScreen}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
Run Code Online (Sandbox Code Playgroud)
我是否需要使用某种甚至侦听器重定向到大厅屏幕,还是应该将路径传递到makeUrl地图到屏幕?
使用Claudia JS构建Facebook messenger机器人并计划在AWS Lambda上托管.
我想问一下用户一系列问题.
当用户回答答案时,我需要保存以供日后使用,一旦我掌握了所需的所有信息,我会将答案传递给函数.
保存此信息的最佳方法是什么?
我正在考虑一些缓存层,例如redis,但因为存储在RAM中,当lamda服务器关闭时我会丢失它.Mongodb在连接时显然有很多开销,但至少会持久.
也许只是一个简单的mySQL服务器?
别人怎么做?我觉得有一个我想念的简单解决方案.
node.js ×4
javascript ×3
mongodb ×2
apollo ×1
aws-lambda ×1
axios ×1
bash ×1
chatbot ×1
contentful ×1
css ×1
database ×1
deep-linking ×1
devops ×1
ecmascript-6 ×1
expo ×1
gm ×1
graphql ×1
html ×1
imagemagick ×1
nginx ×1
react-apollo ×1
react-native ×1
reactjs ×1