【问题标题】:What is the proper configuration for a NextJs app running on Google App Engine?在 Google App Engine 上运行的 NextJs 应用程序的正确配置是什么?
【发布时间】:2020-02-27 17:50:23
【问题描述】:

我觉得我已经尝试了 app.yaml 和 next.config.js 中的所有内容,所以我只是想问,让 NextJs 应用程序在 Google App Engine 上运行的正确配置是什么?

我能够让它工作的唯一方法是删除 <Link href="..."> 的所有实例并使用以下 app.yaml。

runtime: nodejs10

service: default
handlers:
  - url: /.*
      secure: always
      script: auto

env_variables:
  ...

我试过以下没有运气

runtime: nodejs10

service: default
handlers:
  - url: /_next
    static_dir: .next
    secure: always
  - url: /static
    static_dir: static
    secure: always
  - url: /.*
    secure: always
    script: auto

env_variables:
  ...

这是我正在使用的模块版本。

"dependencies": {
    "@zeit/next-css": "^1.0.1",
    "@zeit/next-sass": "^1.0.1",
    "@zeit/next-workers": "1.0.1-canary.1",
    "apollo-cache-inmemory": "^1.6.3",
    "apollo-client": "^2.6.4",
    "apollo-link-http": "^1.5.16",
    "autoprefixer": "^9.6.4",
    "cannon": "^0.6.2",
    "compression": "^1.7.4",
    "d3-ease": "^1.0.5",
    "express": "^4.17.1",
    "firebase": "^7.2.1",
    "firebase-admin": "^8.6.1",
    "graphql": "^14.5.8",
    "graphql-tag": "^2.10.1",
    "gsap": "^2.1.3",
    "imagemin-mozjpeg": "^8.0.0",
    "imagemin-optipng": "^7.1.0",
    "imagemin-pngquant": "^8.0.0",
    "imagemin-svgo": "^7.0.0",
    "isomorphic-unfetch": "^3.0.0",
    "next": "9.1.2",
    "next-compose-plugins": "^2.2.0",
    "next-fonts": "^0.18.0",
    "next-images": "^1.2.0",
    "next-optimized-images": "^2.5.3",
    "next-react-svg": "1.1.0",
    "node-sass": "^4.12.0",
    "postcss-loader": "^3.0.0",
    "react": "16.11.0",
    "react-cookie": "^4.0.1",
    "react-dom": "16.11.0",
    "react-ga": "^2.7.0",
    "react-howler": "^3.7.4",
    "react-icons": "^3.7.0",
    "react-no-ssr": "^1.1.0",
    "react-progress-label": "^3.1.3",
    "react-resize-detector": "^4.2.0",
    "react-scroll": "^1.7.14",
    "react-slick": "^0.25.2",
    "react-spring": "^8.0.27",
    "shortid": "^2.2.15",
    "styled-jsx": "3.2.1",
    "tailwindcss": "^1.1.2",
    "three": "^0.108.0"
},
"devDependencies": {
    "@storybook/addon-a11y": "^5.2.0",
    "@storybook/addon-actions": "^5.2.1",
    "@storybook/addon-backgrounds": "^5.2.0",
    "@storybook/addon-console": "^1.2.1",
    "@storybook/addon-knobs": "^5.2.1",
    "@storybook/addon-links": "^5.2.1",
    "@storybook/addon-viewport": "^5.2.0",
    "@storybook/addons": "^5.2.1",
    "@storybook/react": "^5.2.1",
    "@storybook/storybook-deployer": "^2.8.1",
    "babel-eslint": "^10.0.3",
    "babel-jest": "^24.9.0",
    "babel-loader": "^8.0.6",
    "babel-plugin-inline-react-svg": "^1.1.0",
    "chalk": "^2.4.2",
    "dopl": "^0.2.0",
    "entities": "^2.0.0",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.14.0",
    "eslint": "^6.4.0",
    "eslint-config-airbnb": "^18.0.1",
    "eslint-loader": "^3.0.0",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.14.3",
    "eslint-plugin-react-hooks": "^2.2.0",
    "gulp": "^4.0.2",
    "jest": "^24.9.0",
    "minimist": "^1.2.0",
    "packpath": "^0.1.0",
    "react-generate-props": "^0.6.0",
    "require-context.macro": "^1.1.1",
    "storybook-loader": "^0.1.4",
    "worker-loader": "^2.0.0"
}

【问题讨论】:

  • 据我所知,无论您在next.config.js 中以distDir 的形式输入什么内容,它仍会通过GCP 在_next 中查找文件。 const nextConfig = { distDir: 'anotherFolder', ... }
  • 我已将其转换为节点模块。见npmjs.com/package/@layerframers/whereami

标签: node.js reactjs google-app-engine google-cloud-platform next.js


【解决方案1】:

以防万一其他人偶然发现这个,吃这个小金块。它将帮助您让 NextJS 在 GAE(Google App Engine)上使用本地同构提取。我已将其转换为模块。见@layerframers/whereami

https://gist.github.com/robksawyer/476e05c2f6a34f4f48ca4fc33e01bd91

【讨论】:

    【解决方案2】:

    使用 SSR(服务器端渲染)时,请确保检查预期代码是否在服务器或浏览器上运行。如果 getIntialProps 在浏览器上运行时从 localhost 获取,您的代码将会中断。

    【讨论】:

      猜你喜欢
      • 2012-05-27
      • 2012-05-24
      • 1970-01-01
      • 2013-12-20
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 2014-12-27
      相关资源
      最近更新 更多