diff --git a/package.json b/package.json index 2dbe60e..fbe4c72 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "dependencies": { "@sentry/electron": "^1.3.0", "body-parser": "^1.19.0", + "cors": "^2.8.5", "electron-updater": "^4.3.1", "element-ui": "^2.13.1", "express": "^4.17.1", diff --git a/src/main/index.js b/src/main/index.js index 1eaa315..e292498 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -164,8 +164,11 @@ function createTray () { function startHttpServer () { const express = require('express') const app = express() + const cors = require('cors') const bodyParser = require('body-parser') const apiRouter = require('../api/apirouter') + // 配置cors解决跨域请求的问题 + app.use(cors()) // 给app配置bodyParser中间件 // 通过如下配置再路由种处理request时,可以直接获得post请求的body部分 app.use(bodyParser.urlencoded({ extended: true })) diff --git a/yarn.lock b/yarn.lock index a28c048..4c175b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3269,6 +3269,14 @@ core-util-is@1.0.2, core-util-is@~1.0.0: resolved "https://registry.npm.taobao.org/core-util-is/download/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= +cors@^2.8.5: + version "2.8.5" + resolved "https://registry.npm.taobao.org/cors/download/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" + integrity sha1-6sEdpRWS3Ya58G9uesKTs9+HXSk= + dependencies: + object-assign "^4" + vary "^1" + crc32-stream@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/crc32-stream/download/crc32-stream-2.0.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrc32-stream%2Fdownload%2Fcrc32-stream-2.0.0.tgz#e3cdd3b4df3168dd74e3de3fbbcb7b297fe908f4" @@ -7830,7 +7838,7 @@ oauth-sign@~0.9.0: resolved "https://registry.npm.taobao.org/oauth-sign/download/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455" integrity sha1-R6ewFrqmi1+g7PPe4IqFxnmsZFU= -object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: +object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.npm.taobao.org/object-assign/download/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= @@ -10782,7 +10790,7 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -vary@~1.1.2: +vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.npm.taobao.org/vary/download/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=