FileMiddleware from Xcode Project docs (#768)

* Add FileMiddleware in an Xcode Project explanation.

* Delete extra space.

* Update docs/advanced/middleware.md

* Update docs/advanced/middleware.md

---------

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
This commit is contained in:
Eldar Sadykov 2023-04-11 17:48:30 +03:00 committed by GitHub
parent f2987f339e
commit ee90248d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -28,7 +28,7 @@ app.middleware.use(MiddlewareA())
app.middleware.use(MiddlewareB())
app.group(MiddlewareC()) {
$0.get("hello") { req in
$0.get("hello") { req in
"Hello, middleware."
}
}
@ -124,6 +124,14 @@ app.middleware.use(file)
Once `FileMiddleware` is registered, a file like `Public/images/logo.png` can be linked from a Leaf template as `<img src="/images/logo.png"/>`.
If your server is contained in an Xcode Project, such as an iOS app, use this instead:
```swift
let file = try FileMiddleware(bundle: .main, publicDirectory: "Public")
```
Also make sure to use Folder References instead of Groups in Xcode to maintain folder structure in resources after building the application.
## CORS Middleware
Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. REST APIs built in Vapor will require a CORS policy in order to safely return requests to modern web browsers.