GVKun编程网logo

如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?

1

如果您对如何让用户将他们的自定义域连接到我在GoogleAppEngine上托管的next.js应用程序?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何让用户将他们的自

如果您对如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?的详细内容,并且为您提供关于(next 10) - 将 basePath 添加到 next.config.js 时,next-pwa 不起作用、Express engine 学习笔记 - app.engine 的使用方法、Google App Engine app.yaml PHP脚本参数、Google App Engine 上的 Next-JS 应用程序 - 找不到有效的构建的有价值信息。

本文目录一览:

如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?

如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?

如何解决如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?

我开发了一个 next.js 应用,每个人都可以在其中设计自己的个人资料页面。

今天,每个人都使用唯一的子域,例如 jake.app-name.com 和 ben.app-name.com。

我想让每个人都可以选择连接他自己的域以指向他的个人资料页面,例如 jake.com。

我知道如何在域指向服务器后在服务器上管理它。

我的问题是如何使用代码 (API) 将多个域连接到我的 google 应用程序引擎,将来没有任何限制?需要什么? Google 会自动管理所有 SSL 证书吗?我会产生额外费用吗?

谢谢。

解决方法

我在 2021 年还没有研究过这个问题,但截至去年,这是不可能的。您必须手动将每个唯一域映射到您的子域之一。

关于 SSL 证书,请注意 Google 中的以下内容 ....如果您使用子域,则每个基本域每周最多只能有 20 个托管证书。 ..

(next 10) - 将 basePath 添加到 next.config.js 时,next-pwa 不起作用

(next 10) - 将 basePath 添加到 next.config.js 时,next-pwa 不起作用

如何解决(next 10) - 将 basePath 添加到 next.config.js 时,next-pwa 不起作用

我正在使用 nextJS 版本“10.0.9”和 next-pwa 版本“^5.0.6”,它们一起工作得很好,我的应用程序无法满足,但由于某些原因,我需要为所有路由添加前缀所以我在 next.config.js 文件中添加“basePath”属性并将其设置为“/recharge-cards”,但在那之后我的应用程序变得可卸载我尝试了很多事情我将范围和子域前缀更改为“/recharge -cards”并更改我的 _document.js 上的文件路径,但似乎没有任何效果。

你会在下面找到我的文件,帮助我解决这个问题

manifest.json

{
  "name": "next-pwa","short_name": "next-pwa","display": "standalone","orientation": "portrait","theme_color": "#FFFFFF","background_color": "#FFFFFF","start_url": "/recharge-cards","icons": [
    {
      "src": "/android-chrome-192x192.png","sizes": "192x192","type": "image/png","purpose": "maskable"
    },{
      "src": "/icon-512x512.png","sizes": "512x512","type": "image/png"
    }
  ]
}

next.config.js

const withPWA = require(''next-pwa'');

module.exports = withPWA({
    basePath: "recharge-cards",pwa: {
    dest: ''public'',},});

_document.js(头部)

<Head>
  <Meta name=''application-name'' content={APP_NAME} />
  <Meta name=''apple-mobile-web-app-capable'' content=''yes'' />
  <Meta name=''apple-mobile-web-app-status-bar-style'' content=''default'' />
  <Meta name=''apple-mobile-web-app-title'' content={APP_NAME} />
  <Meta name=''description'' content={APP_DESCRIPTION} />
  <Meta name=''format-detection'' content=''telephone=no'' />
  <Meta name=''mobile-web-app-capable'' content=''yes'' />
  <Meta name=''theme-color'' content=''#FFFFFF'' />
  <link rel=''apple-touch-icon'' sizes=''180x180'' href=''/apple-touch-icon.png'' />
  <link rel=''manifest'' href=''/manifest.json'' />
  <link rel=''shortcut icon'' href=''/favicon.ico'' />
</Head>

项目文件

解决方法

经过多次实验,我解决了,下面你会找到我的解决方案

manifest.json

{
  "name": "Nana digital goods","short_name": "Nana Digital","display": "standalone","orientation": "portrait","theme_color": "#227a40","background_color": "#fff","start_url": "/recharge-cards/","icons": [
    {
      "src": "/recharge-cards/assets/images/android-chrome-192x192.png","sizes": "192x192","type": "image/png","purpose": "maskable"
    },{
      "src": "/recharge-cards/assets/images/android-chrome-512x512.png","sizes": "512x512","type": "image/png"
    }
  ]
}

next.config.js

const withPWA = require(''next-pwa'');
const nextTranslate = require(''next-translate'');
const path = require(''path'');

module.exports = withPWA({
    trailingSlash: true,basePath: ''/recharge-cards'',async redirects() {
    return [
      {
        source: ''/'',destination: ''/recharge-cards'',basePath: false,permanent: false,},]
  },webpackDevMiddleware: config => {
        config.watchOptions = {
            poll: 1000,aggregateTimeout: 300
        }
        return config
    },sassOptions: {
        includePaths: [path.join(__dirname,''styles'')]
    },publicRuntimeConfig: {},...nextTranslate(),pwa: {
    dest: ''public'',subdomainPrefix: ''/recharge-cards/'',scope: ''/''
  },});

_document.js(头部)

<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name=''application-name'' content={APP_NAME} />
<meta name=''apple-mobile-web-app-capable'' content=''yes'' />
<meta name=''apple-mobile-web-app-status-bar-style'' content=''default'' />
<meta name=''apple-mobile-web-app-title'' content={APP_NAME} />
<meta name=''description'' content={APP_DESCRIPTION} />
<meta name=''format-detection'' content=''telephone=no'' />
<meta name=''mobile-web-app-capable'' content=''yes'' />
<meta name=''theme-color'' content=''#227a40'' />
<title>{this.title}</title>
<link rel=''apple-touch-icon'' sizes=''180x180'' href=''/recharge-cards/apple-touch-icon.png'' />
<link rel=''manifest'' href=''/recharge-cards/manifest.json'' />
<link rel=''shortcut icon'' href=''/recharge-cards/favicon.ico'' />
<link rel="icon" type="image/png" sizes="32x32" href="/recharge-cards/assets/images/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/recharge-cards/assets/images/favicon-16x16.png" />

项目文件

Express engine 学习笔记 - app.engine 的使用方法

Express engine 学习笔记 - app.engine 的使用方法

看下面这段代码:

server.engine(
    ''html'',
    ngExpressEngine({
      bootstrap: AppServerModule,
    })
  );

app.engine(ext, callback)

将给定的模板引擎回调注册为 ext。

默认情况下,Express 将根据文件扩展名 require() 引擎。 例如,如果您尝试渲染“foo.pug”文件,Express 会在内部调用以下内容,并在后续调用中缓存 require() 以提高性能。

app.engine(''pug'', require(''pug'').__express)

对于不提供 .__express 开箱即用的引擎,或者如果您希望将不同的扩展“映射”到模板引擎,请使用此方法。

例如,要将 EJS 模板引擎映射到“.html”文件:

app.engine(''html'', require(''ejs'').renderFile)

在这种情况下,EJS 提供了一个 .renderFile() 方法,其签名与 Express 期望的相同:(path, options, callback),但请注意,它在内部将此方法别名为 ejs.__express,因此如果您使用的是“.ejs” 扩展你不需要做任何事情。

某些模板引擎不遵循此约定。 consolidate.js 库映射 Node 模板引擎以遵循此约定,因此它们可以与 Express 无缝协作。

因此本文开头的代码,语义是使用 ngExpressEngine 来渲染 html 文件。

import { ngExpressEngine as engine } from ''@nguniversal/express-engine'';

更多Jerry的原创文章,尽在:“汪子熙”:

本文同步分享在 博客“汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

Google App Engine app.yaml PHP脚本参数

Google App Engine app.yaml PHP脚本参数

在我的GAE PHP app.yaml中,我试图这样做:

application: myapp
version: 1
runtime: PHP
api_version: 1
threadsafe: yes

handlers:

- url: /sitemap.xml    
  static_files: sitemap.xml
  upload: /sitemap\.xml

- url: /MyOneLink
  script: /myDynamicContent.PHP?myparam=hardcoded_value_1

- url: /MySecondLink
  script: /myDynamicContent.PHP?myparam=hardcoded_value_2

因此,可以浏览http://example.com/MyOneLink并获取动态PHP的结果(这取决于硬编码的myparam值)

问题是浏览时没有任何显示.
任何想法 ?

顺便说一句:您可以弄清楚为什么我还要发布“ sitemap.xml”:它将用于公开所有myLinks

谢谢
迭戈

解决方法:

对于有限数量的硬编码值(如问题所示),其他答案将是合适的.

但是,如果您想使用具有无限可能值的真正动态版本,那么您可能会想到以下几点(无效):

- url: /MyLinks/(.*)/?
  script: /myDynamicContent.PHP?myparam=\1

上面的方法不起作用.您可以使用简单的PHP hack解决该问题.

将app.yaml更新为:

- url: /MyLinks/.*
  script: /myDynamicContent.PHP

在myDynamicContent.PHP中,获取$_SERVER [‘REQUEST_URI’]的值,然后解析此字符串以获取myparam的预期值.

更新!更优雅的方法:

<?PHP
$requestURI = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
$requestURI = explode("/", $requestURI);
$myparam = $requestURI[2];
echo $myparam;
?>

Since parse_url always gets the path info, we can safely depend on hardcoded indices. The array produced by explode for string /MyLinks/value_1 will contain an empty string at index 0, MyLinks at 1, value_1 at 2, and so on.

原始的笨重方法:

<?PHP
$requestURI = explode("/", $_SERVER["REQUEST_URI"]);
for ($i = 0; $i < count($requestURI); $i++) {
    if (strcmp($requestURI[$i], "MyLinks") == 0) {
        $myparam = $requestURI[$i + 1];
        break;
    }
}
echo $myparam;
?>

提示:您可以使用单引号’代替双引号“

Google App Engine 上的 Next-JS 应用程序 - 找不到有效的构建

Google App Engine 上的 Next-JS 应用程序 - 找不到有效的构建

如何解决Google App Engine 上的 Next-JS 应用程序 - 找不到有效的构建

在 Google Cloud 的 AppEngine 上部署 Next.js 应用程序后,我收到以下错误消息。在部署应用程序之前,我在本地运行 npm run-scrip build。在本地启动应用程序也能正常工作。

在部署 glcoud app deploy 时,我没有收到任何错误。打开应用 gcloud app browse 后,我收到服务器响应 [500]。

在日志中我发现以下错误:

   Error: Could not find a valid build in the ''/workspace/.next'' directory! Try building your app with ''next build'' before starting the server.
    at Server.readBuildId (/workspace/node_modules/next/dist/next-server/server/next-server.js:137)
    at Server (/workspace/node_modules/next/dist/next-server/server/next-server.js:3)
    at createServer (/workspace/node_modules/next/dist/server/next.js:2)
    at start (/workspace/node_modules/next/dist/server/lib/start-server.js:1)
    at nextStart (/workspace/node_modules/next/dist/cli/next-start.js:19)
    at (/workspace/node_modules/next/dist/bin/next:26)

这是我的 package.json:

{
  "name": "next-project","version": "0.1.0","private": true,"scripts": {
    "dev": "next dev","build": "next build","start": "next start -p 8080","preinstall": "node lock_node_version.js"
  }

app.yaml 文件:

env: standard
runtime: nodejs14
service: default
handlers:
  - url: /.*
    secure: always
    script: auto

编辑/添加

  "dependencies": {
    "@apollo/client": "^3.3.6","@apollo/react-hooks": "^4.0.0","@date-io/date-fns": "^1.3.13","@material-ui/core": "^4.11.2","@material-ui/icons": "^4.11.2","@material-ui/lab": "^4.0.0-alpha.57","@material-ui/pickers": "^3.2.10","apollo-server-micro": "^2.19.0","check-node-version": "^4.1.0","date-fns": "^2.16.1","firebase": "^8.2.2","firebase-admin": "^9.4.2","js-cookie": "^2.2.1","lowdb": "^1.0.0","next": "10.0.3","next-i18next": "^7.0.1","react": "17.0.1","react-dom": "17.0.1","react-material-ui-carousel": "^2.1.1"
  },"devDependencies": {
    "@types/lowdb": "^1.0.9","@types/node": "^14.14.10","@typescript-eslint/eslint-plugin": "^4.9.0","@typescript-eslint/parser": "^4.9.0","eslint": "^7.14.0","eslint-plugin-jsx-a11y": "^6.4.1","eslint-plugin-react": "^7.21.5","eslint-plugin-react-hooks": "^4.2.0","typescript": "^4.1.2"
  },

非常感谢任何帮助!

解决方法

在 App Engine 中部署之前,您可以使用与 build 脚本相同的行为来构建您的应用程序,方法是使用 gcp-build。它在 GCP docs 上有详细记录,这里有一个示例:

 "scripts": {
    "dev": "next dev","gcp-build": "next build","start": "next start -p 8080","preinstall": "node lock_node_version.js"
  }

为了解决评论中的混淆,您可能已经注意到,在文档中,命令 tsc -p . 指定为自定义构建步骤。它的作用是编译 Typescript 代码,因为示例本身就是一个 Typescript 应用程序。除非您使用 Typescript,否则不需要运行它。这始终取决于您,您可以在使用 gcp-build 时自由指定任何命令。

关于如何让用户将他们的自定义域连接到我在 Google App Engine 上托管的 next.js 应用程序?的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于(next 10) - 将 basePath 添加到 next.config.js 时,next-pwa 不起作用、Express engine 学习笔记 - app.engine 的使用方法、Google App Engine app.yaml PHP脚本参数、Google App Engine 上的 Next-JS 应用程序 - 找不到有效的构建等相关内容,可以在本站寻找。

本文标签: