作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个基于 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');
或您想要提供的任何文件名。您还必须删除到 '/'
关于node.js - 如何在 keystone 中提供静态站点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33329974/
我是一名优秀的程序员,十分优秀!