小编qwa*_*g07的帖子

如何在Nginx代理服务器中启用CORS?

作为我的标题,这是位于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)

reverse-proxy nginx node.js cors

16
推荐指数
1
解决办法
4万
查看次数

docker - 启动失败,因为找不到 /etc/fstab

我正在使用 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找不到怎么办?

docker windows-subsystem-for-linux debian-stretch

7
推荐指数
3
解决办法
4980
查看次数

Knex.js - 如何使用“where”子句创建唯一索引?

我正在使用 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”子句创建唯一索引?

postgresql knex.js

3
推荐指数
2
解决办法
6516
查看次数

Mongoosejs - 我可以修改“查找”的后查询中间件中的文档吗?

我正在使用 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)

mongoose node.js

2
推荐指数
1
解决办法
1022
查看次数

JavaScript - 递归函数中的错误是什么?

我尝试获取查询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)

javascript

1
推荐指数
1
解决办法
66
查看次数