简体   繁体   English

如何让 React-Snap 索引完整网站

[英]How to get React-Snap to Index Full Website

I have installed react-snap and want it to index my pages so that they are available for SEO;我已经安装了 react-snap 并希望它为我的页面编制索引,以便它们可用于 SEO; I have integrated with docker per the below dockerfile.我已根据以下 dockerfile 与 docker 集成。 But whenever I do a docker build it says 'crawled 1 out of 1 (/)', so I do not think it is getting my entire site.但是,每当我进行 docker build 时,它都会说“从 1 (/) 中抓取了 1 个”,因此我认为它不会获取我的整个站点。 Does anyone know how to fix?有谁知道如何修复?

The Docker file is: Docker 文件是:

ARG NODE_VERSION=lts

# Dependencies
FROM node:${NODE_VERSION}-slim as dependencies
WORKDIR /home/node/

RUN apt-get update
RUN apt-get install -y build-essential python
RUN npm install --global npm node-gyp

COPY package.json *package-lock.json *.npmrc ./

ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}
RUN npm ci

# Application
FROM node:${NODE_VERSION}-slim as build
WORKDIR /home/node/

COPY --from=dependencies /home/node/node_modules node_modules
COPY . .

ENV PATH="$PATH:/home/node/node_modules/.bin"
ENV NODE_ENV production

###
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    --no-install-recommends
# Install Google Chrome
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
    apt-get -yqq update && \
    apt-get -yqq install google-chrome-stable && \
    rm -rf /var/lib/apt/lists/*

RUN npm run build

# Nginx
FROM nginx:1.16

COPY --from=build /home/node/build /var/www
COPY conf.nginx /etc/nginx/conf.d/default.conf

I also have for package.json:我也有 package.json:

{
  "name": "myapp_web_ui",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@bugsnag/js": "^6.4.3",
    "@bugsnag/plugin-react": "^6.4.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.19",
    "@fortawesome/free-brands-svg-icons": "^5.9.0",
    "@fortawesome/free-regular-svg-icons": "^5.9.0",
    "@fortawesome/free-solid-svg-icons": "^5.9.0",
    "@fortawesome/react-fontawesome": "^0.1.4",
    "animate.css": "^3.7.2",
    "apexcharts": "^3.10.0",
    "firebase": "^6.3.0",
    "js-cookie": "^2.2.1",
    "jsqr": "^1.2.0",
    "lato-font": "^3.0.0",
    "lodash": "^4.17.14",
    "moment": "^2.24.0",
    "node-sass": "^4.12.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-apexcharts": "^1.3.3",
    "react-bootstrap": "^1.0.0-beta.9",
    "react-bootstrap-timezone-picker": "^2.0.0",
    "react-datetime": "^2.16.3",
    "react-dom": "^16.8.6",
    "react-modal": "^3.8.1",
    "react-places-autocomplete": "^7.2.1",
    "react-redux": "^7.0.2",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.2.0",
    "react-snap": "^1.23.0",
    "react-stripe-elements": "^4.0.0",
    "react-tooltip": "^3.10.0",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "typeface-montserrat": "0.0.75",
    "whatwg-fetch": "^3.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint src",
    "serve:prod": "serve -s build -l 4000",
    "postbuild": "react-snap",
    "snap": "react-snap"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "reactSnap": {
     "puppeteerArgs": [
       "--no-sandbox",
       "--disable-setuid-sandbox"
     ]
   },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "serve": "^11.2.0"
  }
}

You need to define the routes to be crawled in advance;需要提前定义要爬取的路由;

// in package.json

"reactSnap": {
    "include": ["/", "/login", "/contact", "/about", ...]
}

By default it only includes "/" so it only crawls that route and ends the process. 默认情况下,它只包含"/"因此它只会抓取该路由并结束该过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 防止react-snap将所有JS脚本链接放入生成的文件中 - Prevent react-snap from putting all JS script links into generated files 与Node互动-如何获取多页网站? - React with Node — How To Get Multiple Page Website? 如何使用 NodeJS MongoDB 获取完整的索引信息以便能够重新创建相同的索引 - How to get full index information using NodeJS MongoDB to be able to recreate the same index 我想知道一些关于如何托管和上传完整网站的事情,包括(服务器、反应、mysql) - i would like to know few things about how to host and upload full website include(server ,react, mysql) 如何使用 Express.js 成功加载 Static 网站,无法获取 /index.html,错误 - How to Successfully Load a Static Website with Express.js, Cannot GET /index.html, error 在尝试抓取 React 网站时获取 index.html 内容 - Getting index.html content while trying to scrape a react website 如何在 Express 中获取完整 URL? - How to get the full URL in Express? 在完整堆栈网站上运行多少个NodeJS项目? - How many NodeJS projects to run on a full stack Website? Vue网站在除索引之外的所有页面上返回“无法获取/路径” - Vue Website Returns “Cannot Get /path” On All Pages EXCEPT Index 如何将 React 添加到已经构建的网站? - How to add React to an already built website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM