用于 NuxtJS 的 Rendertron 和用于 SEO 目的的 Firestore 网站

Rendertron for NuxtJS and Firestore site for SEO purposes

我想为我的 NuxtJS 站点使用 Rendertron

我的 nuxtjs firestore 站点位于 https://ampedcast.com and the rendertron site is here: https://render-tron.appspot.com/

根据google给出的这个例子: https://codelabs.developers.google.com/codelabs/dynamic-rendering#4

我需要将以下几行添加到我的 nuxtjs 站点 https://ampedcast.com 中的 server.js,但我不知道该怎么做。在 nuxtjs 中,您不应该对 server.js.

进行更改
const rendertron = require('rendertron-middleware');

const BOTS = rendertron.botUserAgents.concat('googlebot');
const BOT_UA_PATTERN = new RegExp(BOTS.join('|'), 'i');

app.use(rendertron.makeMiddleware({
  proxyUrl: 'https://ampedcast-7c1d6.uc.r.appspot.com/render',
  userAgentPattern: BOT_UA_PATTERN
}));

任何帮助或指点将不胜感激。

我自己没有使用过 NuxtJS,但是 documentation 它说:

Nuxt.js let you define the server connection variables for your application inside nuxt.config.js.

我假设您可以在那里配置您的服务器设置。您可能还需要一个 Custom API endpoint 并将此部分添加到其中:

app.use(rendertron.makeMiddleware({
  proxyUrl: 'https://ampedcast-7c1d6.uc.r.appspot.com/render',
  userAgentPattern: BOT_UA_PATTERN
}));

然后将中间件添加到nuxt.config.js:

serverMiddleware: [
  { path: "/api", handler: "~/api/rest.js" },
],

我使用过其他做类似事情的框架。我很想知道这是否适合您,或者是否有其他人对此有更好的答案。