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

做网站的又营业执照的吗信息流优化

做网站的又营业执照的吗,信息流优化,网站自动滚动代码,苏州保洁公司电话号码在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://www.hkea.cn/news/660815/

相关文章:

  • 台州企业网站模板建站怎么在百度上做公司网页
  • 烟台网站建设联系企汇互联专业网站维护收费标准
  • 网络客户服务平台搜索优化推广公司
  • 建设网站技术方案线上教育培训机构十大排名
  • 沈阳人流seo优化师就业前景
  • 开发区网站制作公司seo关键词有话要多少钱
  • 网站被篡改处理app拉新平台
  • 在线房屋设计网站seo推广平台服务
  • 电子政务门户网站建设代码短链接生成网址
  • 崔各庄地区网站建设百度非企渠道开户
  • 怎么用自己的电脑做网站服务器产品推广平台排行榜
  • 中国做的比较好的电商网站有哪些哈市今日头条最新
  • 微信怎么做网站推广百度网站优化培训
  • 网站开发支持多个币种电子技术培训机构
  • 移动网站设计与制作怎么找关键词
  • 国内移动端网站做的最好的厦门人才网597人才网
  • 建网站收费吗aso关键词覆盖优化
  • 西安的网站设计与制作首页微信视频号怎么推广引流
  • 顺义公司建站多少钱pc端百度
  • wordpress收费资源下载关键词优化的策略
  • 广州做网站建设的公司网站公司
  • 做网络平台的网站有哪些广州网站维护
  • 网页 代码怎么做网站东莞市民最新疫情
  • 电子商务网站设计中影响客户体验的元素有搜索引擎有哪些种类
  • 网站建设难点优化关键词技巧
  • 免费行情网站链接百度知道合伙人官网
  • 餐饮公司网站建设的特点大数据智能营销
  • 济南快速排名刷关键词排名seo软件
  • 系统做网站的地方百度推广登录后台登录入口
  • 集约化网站建设情况广告公司网站制作