Closed Divix55 closed 3 years ago
This is expected behavior; NIOLeafFiles
by default prohibits access to dot-leading directories/files for security purposes.
This can be configured by removing toVisibleFiles
from NIOLeafFiles.limits
Agree, even removing toVisibleFiles are not needed. Setting working directory in AppCode to project root resolve all problems.
@Divix55 Could you tell me how did you set working directory?
I encountered the same error. So I've set it in the Run/Debug Configurations
window but the error still occurred.
Environment:
@shimbaco you shouldn't need to set the working directory for anything other than Xcode
@0xTim I got it. Thank you for your advice!
How did you solve it @shimbaco? I have the same issue
HI all.
It's all about "build path". A default one is ".build" in a working directory and it can't be changed in Appcode unfortunately (I'm using AppCode 2022.1 EAP).
Try to run your app from shell using:
swift run --build-path build
For AppCode to work you need to reconfigure Leaf and inject different templates source. Try this kind of configuration (it's based on LeafTests source code):
configure.swift
import Vapor
import Leaf
import LeafKit
// configures your application
public func configure(_ app: Application) throws {
// uncomment to serve files from /Public folder
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.views.use(.leaf)
if app.environment == .development {
app.leaf.configuration.rootDirectory = projectFolder
app.leaf.sources = LeafSources.singleSource(NIOLeafFiles(
fileio: app.fileio,
limits: [.default],
sandboxDirectory: projectFolder,
viewDirectory: templateFolder
))
}
// register routes
try routes(app)
}
fileprivate var templateFolder: String {
return projectFolder + "Resources/Views/"
}
fileprivate var projectFolder: String {
let folder = #file.split(separator: "/").dropLast(3).joined(separator: "/")
return "/" + folder + "/"
}
Regards!
Describe the bug
Vapor cannot render a webpage templated in leaf, if AppCode from JetBrains is used. JetBrains by default use a .build directory in project root directory to store dependencies and build files. Because of that, LeafKit returns error:
[ ERROR ] LeafError(file: "<absolute path to my project root>/.build/checkouts/leaf-kit/Sources/LeafKit/LeafSource/NIOLeafFiles.swift", function: "file(template:escape:on:)", line: 89, column: 57, reason: LeafKit.LeafError.Reason.illegalAccess("Attempted to access .build")) [request-id: 6468838E-F42F-4252-8AC7-04BEBE2485AF]
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Webpage render correctly.
Environment