Skip to content

Commit

Permalink
1st
Browse files Browse the repository at this point in the history
  • Loading branch information
webocrat committed Nov 21, 2020
1 parent 9d8b6f0 commit a680797
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 5 deletions.
142 changes: 142 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"object": {
"pins": [
{
"package": "async-http-client",
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
"state": {
"branch": null,
"revision": "0a8dddbe15cd72f7bb5e47951fb7c1eb0836dfc2",
"version": "1.2.2"
}
},
{
"package": "async-kit",
"repositoryURL": "https://github.com/vapor/async-kit.git",
"state": {
"branch": null,
"revision": "7457413e57dbfac762b32dd30c1caf2c55a02a3d",
"version": "1.2.0"
}
},
{
"package": "console-kit",
"repositoryURL": "https://github.com/vapor/console-kit.git",
"state": {
"branch": null,
"revision": "7454e839bc5ae0e75c3946d2613e442fd342fe6b",
"version": "4.2.4"
}
},
{
"package": "routing-kit",
"repositoryURL": "https://github.com/vapor/routing-kit.git",
"state": {
"branch": null,
"revision": "4cf052b78aebaf1b23f2264ce04d57b4b6eb5254",
"version": "4.2.0"
}
},
{
"package": "swift-backtrace",
"repositoryURL": "https://github.com/swift-server/swift-backtrace.git",
"state": {
"branch": null,
"revision": "f2fd8c4845a123419c348e0bc4b3839c414077d5",
"version": "1.2.0"
}
},
{
"package": "swift-crypto",
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "9680b7251cd2be22caaed8f1468bd9e8915a62fb",
"version": "1.1.2"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "173f567a2dfec11d74588eea82cecea555bdc0bc",
"version": "1.4.0"
}
},
{
"package": "swift-metrics",
"repositoryURL": "https://github.com/apple/swift-metrics.git",
"state": {
"branch": null,
"revision": "e382458581b05839a571c578e90060fff499f101",
"version": "2.1.1"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "2f9ea477387806a79a8951524ef2d40de917a0e1",
"version": "2.24.0"
}
},
{
"package": "swift-nio-extras",
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
"state": {
"branch": null,
"revision": "e5b5d191a80667a14827bfeb0ae4a511f7677942",
"version": "1.7.0"
}
},
{
"package": "swift-nio-http2",
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
"state": {
"branch": null,
"revision": "78ddbdfca10f64e4399da37c63372fd8db232152",
"version": "1.15.0"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "eb102ad32add8638410e37a69bc815ea11379813",
"version": "2.10.0"
}
},
{
"package": "swift-nio-transport-services",
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
"state": {
"branch": null,
"revision": "bb56586c4cab9a79dce6ec4738baddb5802c5de7",
"version": "1.9.0"
}
},
{
"package": "vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "b040f90b80ac5906fcf1476a46d360c159f01892",
"version": "4.35.0"
}
},
{
"package": "websocket-kit",
"repositoryURL": "https://github.com/vapor/websocket-kit.git",
"state": {
"branch": null,
"revision": "2b06a70dfcfa76a2e5079f60e3ae911511f09db0",
"version": "2.1.2"
}
}
]
},
"version": 1
}
33 changes: 28 additions & 5 deletions Sources/App/routes.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import Vapor

var urls: [String] = [
"https://odisseylife.com/charcoal/",
"https://www.emag.ro/monitor-led-ips-philips-28-4k-uhd-60hz-adaptive-sync-hdmi-displayport-288e2a-00/pd/DZBH32MBM/"
]

var currentIndex = 0
let mutex = DispatchSemaphore(value: 1)

func routes(_ app: Application) throws {
app.get { req in
return "It works!"
}
app.get { req -> Response in
mutex.wait()
defer { mutex.signal() }
if currentIndex == urls.count - 1 {
currentIndex = 0
} else {
currentIndex += 1
}
print(currentIndex)
let url: String = urls[currentIndex]

app.get("hello") { req -> String in
return "Hello, world!"
// Response(status: .continue, version: <#T##HTTPVersion#>, headers: <#T##HTTPHeaders#>, body: <#T##Response.Body#>)
return Response(status: .seeOther, headers: ["Location": url])
}

app.get("urls") { req -> Response in
let urlList = urls.reduce(into: "") { $0 += "<p>\($1)</p>"}
let response = Response(status: .ok,
headers: ["Content-Type": "text/html"],
body: Response.Body(string: "<html>\(urlList)</html>"))
return response
}
}

0 comments on commit a680797

Please sign in to comment.