From 7d5064bfcc3aebfbcd4879d7b493d02f3fe52c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=BF=83=E5=AE=87?= Date: Mon, 15 Jan 2024 11:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E3=80=81re?= =?UTF-8?q?adme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ config/ssrUrl.js | 1 + server/index.js | 5 +++-- src/services/project.js | 3 ++- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 config/ssrUrl.js diff --git a/README.md b/README.md index cc5d75f80..74bdf4fdc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,42 @@ +# gitlink-ssr版本 + + +#### node版本 +12.x +#### ng配置 + +``` +if ($http_user_agent ~* "googlebot|Mediapartners-Google|bingbot|google-structured-data-testing-tool|baiduspider|360Spider|Sogou Spider|Yahoo! Slurp China|^$") + {#判断如果是网络爬虫,转发到node服务器下 + proxy_pass http://www.test.com:3000; + break; + } +``` + +#### 依赖安装、运行 + +```bash +// 依赖 +npm install +npm install pm2 -g + +// 打包 +npm run build +npm run build:server + +// 启动服务 +npm run pm2 + +``` +或者 +```bash +./build.sh +``` + + + + +

前端react环境安装:

1、 安装node v6.9.x;此安装包含了node和npm。

2、 安装cnpm(命令行): npm install -g cnpm --registry=https://registry.npm.taobao.org

diff --git a/config/ssrUrl.js b/config/ssrUrl.js new file mode 100644 index 000000000..83d7698cc --- /dev/null +++ b/config/ssrUrl.js @@ -0,0 +1 @@ +export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : 'http://172.20.32.202:4000' \ No newline at end of file diff --git a/server/index.js b/server/index.js index 77ef87108..031eb4ad8 100644 --- a/server/index.js +++ b/server/index.js @@ -1,12 +1,13 @@ import express from "express"; import "./window" import {render} from "./render"; +import { url } from "../config/ssrUrl"; const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); app.use('/build', express.static('build')); -const targetServer = 'http://172.20.32.202:4000'; // Java 服务器的地址 +const targetServer = url; // Java 服务器的地址 const options = { target: targetServer, changeOrigin: true, // 允许在请求头中更改主机 @@ -37,7 +38,7 @@ app.get('*',function (req,res) { render(req,res); }) -const port = 5000 +const port = 3000 console.log(`\n==> 🌎 Listening on port ${port}. Open up http://localhost:${port}/ in your browser.\n`) app.listen(port, '0.0.0.0'); \ No newline at end of file diff --git a/src/services/project.js b/src/services/project.js index b79e91795..77dacbd91 100644 --- a/src/services/project.js +++ b/src/services/project.js @@ -1,6 +1,7 @@ import axios from 'axios'; +import { url } from '../../config/ssrUrl'; -const baseUrl = 'http://172.20.32.202:4000/api' +const baseUrl = `${url}/api` // export async function getProjectFunc (owner, projectsId) {