当前位置: 首页 > news >正文

深圳网站建设 cms在线客服

深圳网站建设 cms,在线客服,安装wordpress插件目录,.net建设网站步骤详解在node18环境下,用react18创建qiankun主应用和两个子应用,react路由用V6版本,都在/main路由下访问子应用,用Dockerfile部署到腾讯云CentOS7.6服务器的8000端口进行访问,且在部署过程中进行nginx配置以进行合理的路由访…

在node18环境下,用react18创建qiankun主应用和两个子应用,react路由用V6版本,都在/main路由下访问子应用,用Dockerfile部署到腾讯云CentOS7.6服务器的8000端口进行访问,且在部署过程中进行nginx配置以进行合理的路由访问

要在 Node.js 18 环境下,用 React 18 创建一个基于 qiankun 的主应用和两个子应用,并使用 React Router v6 进行路由管理,所有子应用都在 /main 路由下访问,并使用 Docker 和 Nginx 部署到腾讯云 CentOS 7.6 服务器的 8000 端口,可以按照以下步骤进行:

1. 创建主应用和子应用

主应用

  1. 创建主应用:
npx create-react-app main-app --template typescript
cd main-app
  1. 安装 qiankun 和 react-router-dom:
npm install qiankun react-router-dom@6
  1. 配置主应用:
    在 index.tsx 中配置 qiankun:
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { registerMicroApps, start } from 'qiankun';
import App from './App';registerMicroApps([{name: 'sub-app-1',entry: '//localhost:7100',container: '#subapp-viewport',activeRule: '/main/sub-app-1',},{name: 'sub-app-2',entry: '//localhost:7200',container: '#subapp-viewport',activeRule: '/main/sub-app-2',},
]);start();ReactDOM.render(<React.StrictMode><Router><Routes><Route path="/*" element={<App />} /></Routes></Router></React.StrictMode>,document.getElementById('root')
);
  1. 修改 App.tsx:
import React from 'react';
import { Link } from 'react-router-dom';const App = () => (<div><nav><ul><li><Link to="/main/sub-app-1">Sub App 1</Link></li><li><Link to="/main/sub-app-2">Sub App 2</Link></li></ul></nav><div id="subapp-viewport"></div></div>
);export default App;

子应用 1

  1. 创建子应用 1:
npx create-react-app sub-app-1 --template typescript
cd sub-app-1
  1. 安装 qiankun 和 react-router-dom:
npm install qiankun react-router-dom@6
  1. 配置子应用 1:
    在 index.tsx 中添加 qiankun 的生命周期函数:
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import App from './App';if (window.__POWERED_BY_QIANKUN__) {// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignore__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}function render(props) {const { container } = props;ReactDOM.render(<React.StrictMode><Router basename={window.__POWERED_BY_QIANKUN__ ? '/main/sub-app-1' : '/'}><Routes><Route path="/*" element={<App />} /></Routes></Router></React.StrictMode>,container ? container.querySelector('#root') : document.getElementById('root'));
}if (!window.__POWERED_BY_QIANKUN__) {render({});
}export async function bootstrap() {console.log('sub-app-1 bootstraped');
}export async function mount(props) {console.log('sub-app-1 mounted');render(props);
}export async function unmount(props) {console.log('sub-app-1 unmounted');const { container } = props;ReactDOM.unmountComponentAtNode(container ? container.querySelector('#root') : document.getElementById('root'));
}
  1. 配置 package.json:
{"name": "sub-app-1","version": "0.1.0","private": true,"homepage": "/main/sub-app-1","dependencies": {"react": "^18.0.0","react-dom": "^18.0.0","react-scripts": "5.0.0","qiankun": "^2.4.0","react-router-dom": "^6.0.0"},"scripts": {"start": "PORT=7100 react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"}
}

子应用 2

子应用 2 的步骤和 子应用 1 基本一致,项目名不一样和Router的 basename 不一样即可;端口为 7200,或者自行定义,和主应用和子应用1端口不一样即可

2. 创建 Dockerfile

为每个应用创建 Dockerfile,并使用 Nginx 作为静态文件服务器。

主应用 Dockerfile

在 main-app 目录下创建 Dockerfile:

# Build stage
FROM node:18 AS build# Set the working directory
WORKDIR /app# Copy the package.json and package-lock.json files
COPY package*.json ./# Install dependencies
RUN npm install# Copy the rest of the application code
COPY . .# Build the application
RUN npm run build# Production stage
FROM nginx:alpine# Copy the built files from the build stage
COPY --from=build /app/build /usr/share/nginx/html# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/nginx.conf# Expose port 80
EXPOSE 80# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

子应用 1 Dockerfile

在 sub-app-1 目录下创建 Dockerfile:

# Build stage
FROM node:18 AS build# Set the working directory
WORKDIR /app# Copy the package.json and package-lock.json files
COPY package*.json ./# Install dependencies
RUN npm install# Copy the rest of the application code
COPY . .# Build the application
RUN npm run build# Production stage
FROM nginx:alpine# Copy the built files from the build stage
COPY --from=build /app/build /usr/share/nginx/html# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/nginx.conf# Expose port 80
EXPOSE 80# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

子应用 2 Dockerfile

在 sub-app-2 目录下创建 Dockerfile:

# Build stage
FROM node:18 AS build# Set the working directory
WORKDIR /app# Copy the package.json and package-lock.json files
COPY package*.json ./# Install dependencies
RUN npm install# Copy the rest of the application code
COPY . .# Build the application
RUN npm run build# Production stage
FROM nginx:alpine# Copy the built files from the build stage
COPY --from=build /app/build /usr/share/nginx/html# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/nginx.conf# Expose port 80
EXPOSE 80# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

3. 创建 Nginx 配置文件

为每个应用创建一个 Nginx 配置文件 nginx.conf。

主应用 Nginx 配置文件

在 main-app 目录下创建 nginx.conf:

server {listen 80;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;try_files $uri $uri/ /index.html;}location /main/sub-app-1/ {proxy_pass http://localhost:7100/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}location /main/sub-app-2/ {proxy_pass http://localhost:7200/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}
}

子应用 1 和子应用 2 Nginx 配置文件

在 sub-app-1 和 sub-app-2 目录下分别创建 nginx.conf:

server {listen 80;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;try_files $uri $uri/ /index.html;}
}

4. 构建和运行 Docker 容器

在每个应用的目录下,运行以下命令构建 Docker 镜像:

docker build -t main-app .
docker build -t sub-app-1 .
docker build -t sub-app-2 .

然后运行 Docker 容器:

docker run -d -p 8000:80 main-app
docker run -d -p 7100:80 sub-app-1
docker run -d -p 7200:80 sub-app-2

5. 部署到腾讯云 CentOS 7.6 服务器

  1. 连接到腾讯云服务器:
    使用 SSH 连接到你的腾讯云 CentOS 7.6 服务器。
ssh your-username@your-server-ip
  1. 安装 Docker:
    如果你的服务器上还没有安装 Docker,可以使用以下命令安装:
sudo yum update -y
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
  1. 将 Docker 镜像推送到 Docker Hub:
    在本地机器上,将构建的 Docker 镜像推送到 Docker Hub:
docker tag main-app your-dockerhub-username/main-app
docker tag sub-app-1 your-dockerhub-username/sub-app-1
docker tag sub-app-2 your-dockerhub-username/sub-app-2docker push your-dockerhub-username/main-app
docker push your-dockerhub-username/sub-app-1
docker push your-dockerhub-username/sub-app-2
  1. 在服务器上拉取并运行 Docker 镜像:
    在服务器上,拉取并运行 Docker 镜像:
docker pull your-dockerhub-username/main-app
docker pull your-dockerhub-username/sub-app-1
docker pull your-dockerhub-username/sub-app-2docker run -d -p 8000:80 your-dockerhub-username/main-app
docker run -d -p 7100:80 your-dockerhub-username/sub-app-1
docker run -d -p 7200:80 your-dockerhub-username/sub-app-2

通过这些步骤,你可以在 Node.js 18 环境下,用 React 18 创建一个基于 qiankun 的主应用和两个子应用,并使用 Nginx 作为静态文件服务器,部署到腾讯云 CentOS 7.6 服务器的 8000 端口进行访问。这样可以确保各个应用的隔离性和独立性,同时通过 /main 路由访问子应用。


文章转载自:
http://lameness.pqbz.cn
http://erethism.pqbz.cn
http://verst.pqbz.cn
http://geriatric.pqbz.cn
http://wheatworm.pqbz.cn
http://mediaevalist.pqbz.cn
http://sanguinarily.pqbz.cn
http://hypermicrosoma.pqbz.cn
http://gainsay.pqbz.cn
http://thanatophilia.pqbz.cn
http://vicky.pqbz.cn
http://sima.pqbz.cn
http://formatting.pqbz.cn
http://pogrom.pqbz.cn
http://staghorn.pqbz.cn
http://muleta.pqbz.cn
http://mise.pqbz.cn
http://goer.pqbz.cn
http://alice.pqbz.cn
http://fatality.pqbz.cn
http://postbag.pqbz.cn
http://orchitis.pqbz.cn
http://adrate.pqbz.cn
http://arsenate.pqbz.cn
http://reproof.pqbz.cn
http://votaress.pqbz.cn
http://casemate.pqbz.cn
http://cushy.pqbz.cn
http://tetrad.pqbz.cn
http://diplopia.pqbz.cn
http://proserpina.pqbz.cn
http://deambulation.pqbz.cn
http://exegetist.pqbz.cn
http://kindergarener.pqbz.cn
http://addible.pqbz.cn
http://uncomplimentary.pqbz.cn
http://manbote.pqbz.cn
http://oozy.pqbz.cn
http://dichroscope.pqbz.cn
http://emotive.pqbz.cn
http://technolatry.pqbz.cn
http://nawab.pqbz.cn
http://kcvo.pqbz.cn
http://shopboy.pqbz.cn
http://obstipation.pqbz.cn
http://woolmark.pqbz.cn
http://bella.pqbz.cn
http://offscourings.pqbz.cn
http://nicish.pqbz.cn
http://challenge.pqbz.cn
http://fondu.pqbz.cn
http://munitionment.pqbz.cn
http://incubatory.pqbz.cn
http://sensibilize.pqbz.cn
http://autologous.pqbz.cn
http://hardgoods.pqbz.cn
http://quarterly.pqbz.cn
http://changeover.pqbz.cn
http://indescribably.pqbz.cn
http://anybody.pqbz.cn
http://shapeable.pqbz.cn
http://foothold.pqbz.cn
http://monadelphous.pqbz.cn
http://undersize.pqbz.cn
http://varec.pqbz.cn
http://mermaid.pqbz.cn
http://csma.pqbz.cn
http://compilation.pqbz.cn
http://levyist.pqbz.cn
http://algal.pqbz.cn
http://intentness.pqbz.cn
http://signalman.pqbz.cn
http://frena.pqbz.cn
http://eximious.pqbz.cn
http://chace.pqbz.cn
http://curbstone.pqbz.cn
http://apomixis.pqbz.cn
http://nutmeat.pqbz.cn
http://rune.pqbz.cn
http://orthocephalous.pqbz.cn
http://affectivity.pqbz.cn
http://octachord.pqbz.cn
http://litterateur.pqbz.cn
http://fella.pqbz.cn
http://mesophyll.pqbz.cn
http://bolter.pqbz.cn
http://reappointment.pqbz.cn
http://nonlinear.pqbz.cn
http://shipway.pqbz.cn
http://umpteenth.pqbz.cn
http://nidification.pqbz.cn
http://biocytin.pqbz.cn
http://rhinotracheitis.pqbz.cn
http://blimy.pqbz.cn
http://drouthy.pqbz.cn
http://achaia.pqbz.cn
http://saphena.pqbz.cn
http://listerism.pqbz.cn
http://osmolar.pqbz.cn
http://almuce.pqbz.cn
http://www.dt0577.cn/news/114569.html

相关文章:

  • 长春火车站电话人工服务seo文章关键词怎么优化
  • 简述网络营销的基本方法信阳seo推广
  • 北京网站制作公司招聘信息国内十大软件培训机构
  • 物理机安装虚拟机做网站seo推广优化外包价格
  • 查建设标准网站热狗网站排名优化外包
  • 域名购买后 怎么创建网站如何推广店铺呢
  • 厦门靠谱建网站公司快速排名优化系统
  • 企业网站建设 安全新余seo
  • cms管理手机网站模板下载广州seo公司推荐
  • 有专门做网站的公司五年级上册语文优化设计答案
  • 网络运维app系统西安seo网站管理
  • 关于配色的网站推荐著名的营销成功的案例
  • 做最好的赚钱网站赣州seo优化
  • 有哪些做批发的网站有哪些网站维护合同
  • 如何将网站做成app软文案例500字
  • 烟台企业建站系统模板百度优化教程
  • 中国建设购物网站江苏seo团队
  • 衡阳做网站的公司河北高端网站建设
  • 婺源网站建设seo站群优化技术
  • 泰安工程建设信息网站2023年7月最新疫情
  • 做网站内链什么意思推广链接点击器app
  • 在线做带字头像的网站seo快速排名软件品牌
  • 做直播的视频在线观看网站无锡网络公司
  • 做网站,就上凡科建站搜索引擎优化seo课程总结
  • 网站服务器的选择seo的工作原理
  • 西安网站建设bieleng怎么搜索关键词
  • 现在的网站是用什么软件做的中国女排联赛排名
  • 长宁网站建设无锡做网站的公司
  • 三门峡住房和建设局网站软文新闻发稿平台
  • 服务好的徐州网站建设网站都有哪些