本地开发CORS的配置

19 阅读1分钟

当进行CORS时,现代浏览器会强制要求https协议。

cert-ctrl是分布式版本的mkcert,是开源的C++实现。不仅从localhost实现https,并且从局域网访问也可以是https。

  1. https://localhost
  2. https://127.0.0.1
  3. https://192.168.3.4

如何实现

进入cert-ctrl创建一个自签发CA,有效期根据你的职业生涯推断,比如20年,然后在所有需要相互访问的机器上安装客户端即可。

证书的配置在网页端编辑,一般只要编辑fromto即可。

{
  "from": [
    "private.key",
    "certificate.pem",
    "chain.pem",
    "fullchain.pem",
    "certificate.der",
    "bundle.pfx",
    "meta.json"
  ],
  "to": [
    "/opt/test-certs/private.key",
    "/opt/test-certs/certificate.pem",
    "",
    "",
    "",
    "",
    ""
  ],
  "cmd": "chown jianglibo:jianglibo /opt/test-certs/private.key;chmod 600 /opt/test-certs/private.key"
}

CA只要和设备关联就会自动导入系统信任的CA。