vapor - 在 Vapor 中将根指向静态网页
问题描述
我有一个静态网页存储在我的 Vapor 服务器的 Public 文件夹中。它有一个 index.html 文件。但是,当我导航到 root (http://localhost:8080) 时,它会显示Not found
.
我需要做什么使根指向 index.html?
解决方案
对于蒸汽 4 ...
在 routes.swift 内部:
app.get { req -> EventLoopFuture<View> in
return req.view.render(app.directory.publicDirectory + "index.html")
}
这假设您在项目目录根目录中有一个“Public”文件夹,其中包含一个 index.html 文件。
此外,在 configure.swift 中:
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
构建项目,运行服务器,并将浏览器指向 localhost:8080,您甚至不必指定 localhost:8080/index.html,它就可以了。
推荐阅读
- c# - WPF:使用“时间”文本框以秒为单位搜索数据库
- scala - 要将应用程序从 Spark 1.5 迁移到 Spark 2.1,我需要做哪些更改?
- c# - 在 C# 类属性中存储函数?
- spring-boot - 使用spring boot mvc无法查看jsp文件
- github - github repo 是否有编程方式来报告支持哪些分支/版本?
- r - 如何在要重复 5000 次的 for 循环中找到相关系数?并保存统计信息
- python - 为python排序波斯语字符串
- javascript - 尝试使用 TDD 编写有意义的测试时何时停止?
- c# - 注册表项的值返回为 null,即使它具有值
- azure - 从 Azure 函数调用 WCF 终结点