我的服务器上有 3 个不同的 docker 容器在端口上运行 -
我想配置我的服务器,以便每当请求命中以下路径时,它应该被重定向到相关容器 -
我已经完成将 /container1 重定向到 localhost:5000。但是,它不提供容器 1 中托管的任何静态文件
我的 nginx.conf 文件 -
#user nobody;
worker_processes 1;
http {
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /container1/ {
proxy_pass http://127.0.0.1:5000;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用react-infinite-scroller 构建类似于facebook 的无限滚动帖子。但是,它在控制台中多次给出相同的错误 -
\n\n\n\n\n“遇到两个具有相同密钥的子项。
\nshdj1289密钥应该\n是唯一的,以便组件在更新时保持其身份。\n非唯一的密钥可能会导致子项重复和/或省略\xe2\x80\x94\n该行为不受支持,并且可能在未来版本中发生变化。”
这是渲染函数
\n\nrender() {\r\n const { loading, userData, circleData, redirectToLogin, posts } = this.state;\r\n return redirectToLogin ? <Redirect to="/" /> : (\r\n <Container>\r\n <h1>Hi {userData.firstName}</h1>\r\n \r\n <InfiniteScroll\r\n loadMore={this.fetchPosts}\r\n hasMore={this.state.hasMore}\r\n useWindow={false}\r\n loader={<div key={0}></div>}\r\n >\r\n {posts.map(p => {\r\n return (<Post key={p.postIdentity} data={p} />);\r\n })}\r\n </InfiniteScroll>\r\n </Container>\r\n )\r\n }Run Code Online (Sandbox Code Playgroud)\r\n这是 fetchPosts 函数 -
\n\nfetchPosts = () => {\r\n const postQuery = {\r\n "PageIndex": …Run Code Online (Sandbox Code Playgroud)我正在使用“Material UI”自动完成组件在我的表单中呈现下拉列表。但是,如果用户想要编辑对象,则下拉列表应显示为自动填充从数据库中获取的任何值。
我尝试使用下面的代码来模拟这种情况
import React, { Component } from 'react';
import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';
export default class Sizes extends Component {
state = {
default: []
}
componentDidMount() {
setTimeout(() => {
this.setState({ default: [...this.state.default, top100Films[37]]})
})
}
render() {
return (
<Autocomplete
id="size-small-standard"
size="small"
options={top100Films}
getOptionLabel={option => option.title}
defaultValue={this.state.default}
renderInput={params => (
<TextField
{...params}
variant="standard"
label="Size small"
placeholder="Favorites"
fullWidth
/>
)}
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
在这里安装组件后,我设置超时并返回应显示在下拉列表中的默认值
但是,它无法在下拉列表中显示该值,并且我在控制台中看到此错误 -
index.js:1375 Material-UI: the `getOptionLabel` method of useAutocomplete …Run Code Online (Sandbox Code Playgroud) 一点背景知识 - 我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端口 3001 的所有请求 -
"proxy": "http://localhost:3001"
Run Code Online (Sandbox Code Playgroud)
现在,当我在 React 应用程序中使用 Axios 对 NodeJS 服务器上的“用户/身份验证”路由发出 POST 请求时,请求正文在 Node 服务器上被解析为空白
const request = {
method: 'POST',
url: `/users/authenticate`,
headers: {
'Content-Type': 'application/json'
},
body: {
email: email,
password: password
}
};
console.log(request);
axios(request).then((res) => {
//handle success
});
}).catch((err) => //handleError ))
Run Code Online (Sandbox Code Playgroud)
但不幸的是,NodeJS 应用程序崩溃了,因为它将 req.body 解析为空白。服务器端的相关代码 -
//in index.js file
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json())
app.use('/users', users);
//in users.js …Run Code Online (Sandbox Code Playgroud) 我有以下数据结构,我需要创建一个匹配给定配置的数字数组 -
{
min: 1000,
max: 10000,
interval: 1000
}
Run Code Online (Sandbox Code Playgroud)
在数组下方输出的正确函数是什么 -
[1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]
Run Code Online (Sandbox Code Playgroud)
它可以通过 for 循环来完成 -
const output = [];
for (let i = input.min; i <= input.max; i += input.interval) {
output.push(i);
}
console.log(output)
Run Code Online (Sandbox Code Playgroud)
但我想看看是否有更简洁的方法来使用 Array.fill & map 来做到这一点 -
new Array((max - min + interval)).fill(undefined).map((_, i) => (i + min))
Run Code Online (Sandbox Code Playgroud) javascript ×4
reactjs ×3
arrays ×1
axios ×1
docker ×1
express ×1
material-ui ×1
nginx ×1
node.js ×1