作为我的标题,这是位于conf.d/api-server.conf中的配置文件
server {
listen 80;
server_name api.localhost;
location / {
add_header 'Access-Control-Allow-Origin' 'http://api.localhost';
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:3000;
}
}
Run Code Online (Sandbox Code Playgroud)
nginx.conf文件与默认文件保持一致.
在我向api.localhost(api.localhost/admin/login)发送请求后,我仍然收到405错误:
XMLHttpRequest cannot load http://api.localhost/admin/login. Response
to preflight request doesn't pass access control check: No 'Access-
Control-Allow-Origin' header is present on the requested resource. …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Window Linux 子系统(Debian 延伸版)。按照 Docker 网站上的说明,我安装了 docker-ce,但无法启动。这是信息:
$ sudo service docker start
grep: /etc/fstab: No such file or directory
[ ok ] Starting Docker: docker.
$ sudo service docker status
[FAIL] Docker is not running ... failed!
Run Code Online (Sandbox Code Playgroud)
/etc/fstab
找不到怎么办?
我正在使用 Knex.js。我想使用 WHERE 子句为我的表创建唯一索引:
db.schema.createTable('newTable', function(t) {
t.increments()
t.string('col1').defaultTo(null)
t.string('col2').notNullable()
t.integer('col3').notNullable()
t.unique(['col1', 'col2', 'col3']).whereNotNull('col1')
t.unique(['col2', 'col3']).whereNull('col1')
})
Run Code Online (Sandbox Code Playgroud)
我尝试为表创建两个部分索引。但是,whereNotNull
不能与unique
函数链接。如何使用“where”子句创建唯一索引?
我正在使用 mongoose.js 版本 5.1.6。有没有办法在查询后自动执行 doc.toObject() find
?我不确定是否可以在 的中间件中做到这一点find
。
schema.post('find', function(docs) {
// Can I change the docs that return by find() by modify the docs here?
})
Run Code Online (Sandbox Code Playgroud) 我尝试获取查询ID的整个路径.例如,getPath(6,rawData)应返回[1,2,6].但是,它返回[6,6,6].当我在代码中尝试console.log时,看起来自调用函数内的节点的值将覆盖外部节点的值.我无法弄清楚递归函数有什么问题.或者有人可以教我一种实现同一目标的新方法?
这是代码:
const getPath = (id, list) => {
if (!list || !Array.isArray(list)) {
return false
}
for (node of list) {
if (node.id === id) {
return [node.id]
}
let res = getPath(id, node.children)
if (res) {
return [node.id, ...res]
}
}
return false
}
const rawData = [{
id: 1,
parent: null,
children: [{
id: 2,
parent: 1,
children: [{
id: 4,
parent: 2,
children: null
}, {
id: 5,
parent: 2,
children: null
}, {
id: 6, …
Run Code Online (Sandbox Code Playgroud)