{"id":1806,"date":"2023-03-27T22:50:18","date_gmt":"2023-03-27T14:50:18","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1806"},"modified":"2023-04-22T09:24:50","modified_gmt":"2023-04-22T01:24:50","slug":"spring-cloud-gray-frontend-production-deployment-record","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/27\/spring-cloud-gray-frontend-production-deployment-record\/","title":{"rendered":"Spring Cloud Gray \u524d\u7aef\u751f\u4ea7\u90e8\u7f72\u8bb0\u5f55"},"content":{"rendered":"<h3>\u53cd\u5411\u4ee3\u7406\u914d\u7f6e<\/h3>\n<pre><code class=\"language-bash\">$ vim vue.config.js<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">  devServer: {\n    port: port,\n    open: true,\n    overlay: {\n      warnings: false,\n      errors: true\n    },\n    proxy: {\n      \/\/ change xxx-api\/login =&gt; mock\/login\n      \/\/ detail: https:\/\/cli.vuejs.org\/config\/#devserver-proxy\n      [process.env.VUE_APP_BASE_API]: {\n        \/\/target: `http:\/\/127.0.0.1:${port}\/mock`,\n        target: &#039;http:\/\/192.168.1.22:9200&#039;,\n        changeOrigin: true,\n        ws: true,\n        pathRewrite: {\n          [&#039;^&#039; + process.env.VUE_APP_BASE_API]: &#039;&#039;,\n        }\n      },\n      \/\/&#039;\/api&#039;: {\n        \/\/target: &#039;http:\/\/192.168.1.22:9200&#039;,\n        \/\/changeOrigin: true,\n        \/\/ws: true,\n        \/\/pathRewrite: {\n          \/\/&#039;^\/api&#039;: &#039;&#039;,\n        \/\/},\n      \/\/}\n    },\n    disableHostCheck: true,\n    \/\/after: require(&#039;.\/mock\/mock-server.js&#039;)\n  },<\/code><\/pre>\n<h3>\u5173\u95edMock<\/h3>\n<pre><code class=\"language-bash\">$ vim src\/main.js<\/code><\/pre>\n<pre><code class=\"language-javascript\">\/**\n * If you don&#039;t want to use mock-server\n * you want to use MockJs for mock api\n * you can execute: mockXHR()\n *\n * Currently MockJs will be used in the production environment,\n * please remove it before going online! ! !\n *\/\n\/\/import { mockXHR } from &#039;..\/mock&#039;\n\/\/if (process.env.NODE_ENV === &#039;production&#039;) {\n  \/\/mockXHR()\n\/\/}<\/code><\/pre>\n<h3>\u7f16\u8bd1<\/h3>\n<p>production\u7f16\u8bd1\u53ef\u63d0\u5347\u8bbf\u95ee\u901f\u5ea6<\/p>\n<pre><code class=\"language-bash\">$ npm run build:prod<\/code><\/pre>\n<h3>Nginx\u914d\u7f6e<\/h3>\n<pre><code class=\"language-json\">server {\n    listen       9527;\n    server_name  localhost;\n\n    location \/ {\n        root   \/home\/yezhou\/spring-cloud-gray-webui\/dist;\n        index  index.html index.htm;\n    }\n\n    location \/prod-api\/ {\n        proxy_set_header Host $host;\n        proxy_set_header x-forwarded-for $remote_addr;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_pass http:\/\/192.168.1.22:9200\/;\n    }\n}<\/code><\/pre>\n<h3>\u6d4b\u8bd5<\/h3>\n<pre><code class=\"language-bash\">curl -X POST http:\/\/192.168.1.22:9200\/gray\/user\/login -H &#039;Content-Type:application\/json&#039; -d &#039;{&quot;username&quot;:&quot;admin&quot;, &quot;password&quot;:&quot;abc123&quot;}&#039;<\/code><\/pre>\n<pre><code class=\"language-json\">{\n    &quot;code&quot;:&quot;0&quot;,\n    &quot;message&quot;:&quot;operation is success&quot;,\n    &quot;data&quot;:{\n        &quot;token&quot;:&quot;eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDU4NTQ3NjksInVzZXJfbmFtZSI6ImFkbWluIiwiYXV0aG9yaXRpZXMiOlsiYWRtaW4iXSwianRpIjoiNjRmNGEyNzEtNDgyYy00ODNhLTg3MWUtYjUwNWVkZTQ3N2JjIiwiY2xpZW50X2lkIjoiZ3JheS1zZXJ2ZXIiLCJzY29wZSI6W119.Lzo0zXtSYOsqtMvN_J8QUGQku9Hdl8BKmriMehbLZZqj9D9eGrt9ROfyngNWi9UmCtVbtO8ubIBB-WbvCGLxUp1WZwCOIF6wyF13MZ6H6XIF1skf3t7nzORUqKTkxDVvkkKy0eX--Z2sfO4TiST8acXzxqXgn1xccZIa1kPb1dvQ8duBlwbQPlpLkqxQfc0R1JBeaDj8Fua19xC0vLUtKuGL6l0cTtgpTuaDAXp8NAvKv8eB2W4BLgqa0ner0_2_VPENz7-HQxlFbufeEMdIrtclSoLuQj9mxH9_mOeK1eNUod2UOfY-gWTud0gfkkYEb02JLaqtcn4u7D7sKFOQ6w&quot;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53cd\u5411\u4ee3\u7406\u914d\u7f6e $ vim vue.config.js devServer: { port: port, ope [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[448],"tags":[450],"class_list":["post-1806","post","type-post","status-publish","format-standard","hentry","category-release","tag-spring-cloud-gray"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1806"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1806\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}