gpt4 book ai didi

node.js - 如何在 keystone 中提供静态站点?

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:26 24 4
gpt4 key购买 nike

我有一个基于 keystone 的网站和一个完全静态的网站。

我想将静态的整合到第一个中。所有对“/”的请求都将服务于静态请求,但“/resources”下的请求将服务于 keystone 站点。

基本上:

"/"            would serve the static folder 'site'
"/resources" would serve the keystone app

目前我的结构是:

public
| - keystone
| - site

我的 keystone 静态选项设置为“public”

    'static': 'public'

我将如何设置这些路由?

我正在考虑以这种方式使用中间件:

app.use("/", express.static(__dirname + "/site"));
app.use("/resources", express.static(__dirname + "/keystone"));

但在 keystone 中我该怎么做呢?

最佳答案

您不需要任何额外的中间件。使用选项 'static' : 'public',放置在项目文件夹内的 public 文件夹中的任何静态内容都将作为静态内容提供。

也可以通过提供一组目录来定义多个目录,例如 'static' : ['public','site'] 这样目录站点中的所有内容也将送达。

我假设您希望在有人访问您的网站根目录时加载某种 index.html。您可以通过向 /routes/index.js 添加重定向来实现。只需添加 keystone.redirect('/', '/index.html'); 或您想要提供的任何文件名。您还必须删除到 '/'

的 keystone 路由

关于node.js - 如何在 keystone 中提供静态站点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33329974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com