是否可以在 nodejs 应用程序中将所有 url 路径重定向到 App Engine 中的根处理程序? [英] Is it possible to redirect all url paths to the root handler in App Engine in a nodejs app?
问题描述
我使用 App Engine 来托管 Nodejs SPA,我不需要路由,所以我想将所有处理程序重定向到根处理程序.示例:将 domain.tld/nsa-secrets
重定向到 domain.tld
我已尝试将处理程序配置为文档中的示例,但我总是得到默认的 not found Apache html.
这是我的app.yaml
:
运行时:nodejs10实例类:F2处理程序:- 网址:/静态文件:dist/index.html上传:dist/index.html- 网址:/静态目录:dist- 网址:/.*安全:始终redirect_http_response_code: 301脚本:自动错误处理程序:- 文件:error.html
我看到一个错误,然后在错误报告中显示:
错误:找不到模块/srv/server.js"在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)在 Function.Module._load (internal/modules/cjs/loader.js:508:25)在 Function.Module.runMain (internal/modules/cjs/loader.js:754:12)启动时(内部/bootstrap/node.js:283:19)在 bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
我是否需要在 server.js
中手动实现一个 url 处理程序?
感谢您的时间和帮助.
您会尝试 Firebase 托管吗?
Firebase 托管比 App Engine 更适合托管 SPA.
见:
- https://firebase.google.com/docs/hosting/use-cases<块引用>
受益于 Firebase Hosting 为单页网络应用和静态网站提供服务的独特优化.静态资产(HTML、CSS、JavaScript、字体等)的交付由我们的 SSD 后端存储和全球 CDN 提供支持,该 CDN 的边缘位置遍布世界所有主要地点.您甚至可以在全球 CDN 上缓存您的动态内容.Firebase 托管的所有网站还可以获得免费的 SSL 证书,因此您的内容始终可以安全地传送.
- https://firebase.google.com/docs/hosting/full-config#rewrites
I'm using App Engine to host a Nodejs SPA, I don't need routes so I would like to redirect all handlers to the root one. Example: redirect domain.tld/nsa-secrets
to domain.tld
I have tried configuring a handler as the example in the documentation, but I always get the default not found Apache html.
Here is my app.yaml
:
runtime: nodejs10
instance_class: F2
handlers:
- url: /
static_files: dist/index.html
upload: dist/index.html
- url: /
static_dir: dist
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
error_handlers:
- file: error.html
I see an error then shows in Error Reporting:
Error: Cannot find module '/srv/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Shall I need to manually implement an url handler in server.js
?
Thanks for the time and help.
Would you try Firebase Hosting?
Firebase Hosting is better than App Engine to hosting a SPA .
See:
- https://firebase.google.com/docs/hosting/use-cases
Benefit from Firebase Hosting's unique optimization for serving single-page web apps and static websites. Delivery of static assets (HTML, CSS, JavaScript, fonts, etc.) is powered by our SSD backend storage and a global CDN with edge locations across all major locations in the world. You can even cache your dynamic content on the global CDN. All sites hosted by Firebase also get a free SSL certificate, so your content is always delivered securely.
- https://firebase.google.com/docs/hosting/full-config#rewrites
这篇关于是否可以在 nodejs 应用程序中将所有 url 路径重定向到 App Engine 中的根处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!