Skip to content

Commit 9bb89b4

Browse files
committed
"created BasicAuth from template https://github.com/vapor/web-template"
0 parents  commit 9bb89b4

26 files changed

+578
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# Created by https://www.gitignore.io/api/vapor
3+
4+
### Vapor ###
5+
Config/secrets
6+
7+
### Vapor Patch ###
8+
Packages
9+
.build
10+
xcuserdata
11+
*.xcodeproj
12+
DerivedData/
13+
.DS_Store
14+
15+
# End of https://www.gitignore.io/api/vapor

Config/app.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"foo": "foo-bar"
3+
}

Config/crypto.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"hash": {
3+
"method": "sha256",
4+
"encoding": "hex",
5+
"key": "0000000000000000"
6+
},
7+
8+
"cipher": {
9+
"method": "aes256",
10+
"encoding": "base64",
11+
"key": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
12+
}
13+
}

Config/droplet.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"//": "The type of server to use for handling requests.",
3+
"//": "engine: Vapor's blazing fast Engine HTTP server.",
4+
"server": "engine",
5+
6+
"//": "The type of client to use for requesting data from other services.",
7+
"//": "engine: Vapor's blazing fast Engine HTTP client.",
8+
"//": "foundation: A wrapper around Foundation's URLSession.",
9+
"client": "engine",
10+
11+
"//": "The type of console to use for displaying information and prompting input.",
12+
"//": "terminal: Vapor's default terminal console.",
13+
"console": "terminal",
14+
15+
"//": "The type of logger to use for recording logs, warnings, errors, etc.",
16+
"//": "console: Vapor's default logger sends logs directly to the chosen console.",
17+
"log": "console",
18+
19+
"//": "The type of hasher to use for hashing messages.",
20+
"//": "crypto: Vapor's default hasher powered by OpenSSL (configure in crypto.json)",
21+
"//": "bcrypt: Performant BCrypt hashing implementation (configure in bcrypt.json)",
22+
"hash": "crypto",
23+
24+
"//": "The type of cipher to use for encrypting and decrypting messages.",
25+
"//": "crypto: Vapor's default cipher powered by OpenSSL (configure in crypto.json)",
26+
"cipher": "crypto",
27+
28+
"//": "The type of view renderer that drop.view will use",
29+
"//": "leaf: Pure Swift templating language created for Vapor.",
30+
"//": "static: Simply return the view at the supplied path",
31+
"view": "leaf",
32+
33+
"//": "Choose which middleware are enabled (and in which order).",
34+
"//": "error: Catches errors thrown in your application and returns a nice response.",
35+
"//": "date: Adds the 'Date' header to HTTP requests.",
36+
"//": "file: Catches 404 errors and checks for files in the Public/ folder",
37+
"middleware": [
38+
"error",
39+
"date",
40+
"file"
41+
],
42+
43+
"//": "Choose which commands this application can run",
44+
"commands": []
45+
}

Config/server.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"//": "The $PORT:8080 call tells the json file to see if there",
3+
"//": "is any value at the 'PORT' environment variable.",
4+
"//": "If there is no value there, it will fallback to '8080'",
5+
"port": "$PORT:8080",
6+
7+
"host": "0.0.0.0",
8+
9+
"//": "It's very rare that a server manages its own TLS.",
10+
"//": "More commonly, vapor is served behind a proxy like nginx.",
11+
"securityLayer": "none"
12+
}

Package.pins

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"autoPin": true,
3+
"pins": [
4+
{
5+
"package": "BCrypt",
6+
"reason": null,
7+
"repositoryURL": "https://github.com/vapor/bcrypt.git",
8+
"version": "1.0.0"
9+
},
10+
{
11+
"package": "Bits",
12+
"reason": null,
13+
"repositoryURL": "https://github.com/vapor/bits.git",
14+
"version": "1.0.0"
15+
},
16+
{
17+
"package": "Console",
18+
"reason": null,
19+
"repositoryURL": "https://github.com/vapor/console.git",
20+
"version": "2.1.0"
21+
},
22+
{
23+
"package": "Core",
24+
"reason": null,
25+
"repositoryURL": "https://github.com/vapor/core.git",
26+
"version": "2.0.2"
27+
},
28+
{
29+
"package": "Crypto",
30+
"reason": null,
31+
"repositoryURL": "https://github.com/vapor/crypto.git",
32+
"version": "2.0.0"
33+
},
34+
{
35+
"package": "CTLS",
36+
"reason": null,
37+
"repositoryURL": "https://github.com/vapor/ctls.git",
38+
"version": "1.0.0"
39+
},
40+
{
41+
"package": "Debugging",
42+
"reason": null,
43+
"repositoryURL": "https://github.com/vapor/debugging.git",
44+
"version": "1.0.0"
45+
},
46+
{
47+
"package": "Engine",
48+
"reason": null,
49+
"repositoryURL": "https://github.com/vapor/engine.git",
50+
"version": "2.0.3"
51+
},
52+
{
53+
"package": "JSON",
54+
"reason": null,
55+
"repositoryURL": "https://github.com/vapor/json.git",
56+
"version": "2.0.2"
57+
},
58+
{
59+
"package": "Leaf",
60+
"reason": null,
61+
"repositoryURL": "https://github.com/vapor/leaf.git",
62+
"version": "2.0.1"
63+
},
64+
{
65+
"package": "LeafProvider",
66+
"reason": null,
67+
"repositoryURL": "https://github.com/vapor/leaf-provider.git",
68+
"version": "1.0.0"
69+
},
70+
{
71+
"package": "Multipart",
72+
"reason": null,
73+
"repositoryURL": "https://github.com/vapor/multipart.git",
74+
"version": "2.0.0"
75+
},
76+
{
77+
"package": "Node",
78+
"reason": null,
79+
"repositoryURL": "https://github.com/vapor/node.git",
80+
"version": "2.0.1"
81+
},
82+
{
83+
"package": "Random",
84+
"reason": null,
85+
"repositoryURL": "https://github.com/vapor/random.git",
86+
"version": "1.0.0"
87+
},
88+
{
89+
"package": "Routing",
90+
"reason": null,
91+
"repositoryURL": "https://github.com/vapor/routing.git",
92+
"version": "2.0.0"
93+
},
94+
{
95+
"package": "Sockets",
96+
"reason": null,
97+
"repositoryURL": "https://github.com/vapor/sockets.git",
98+
"version": "2.0.1"
99+
},
100+
{
101+
"package": "TLS",
102+
"reason": null,
103+
"repositoryURL": "https://github.com/vapor/tls.git",
104+
"version": "2.0.3"
105+
},
106+
{
107+
"package": "Vapor",
108+
"reason": null,
109+
"repositoryURL": "https://github.com/vapor/vapor.git",
110+
"version": "2.0.5"
111+
}
112+
],
113+
"version": 1
114+
}

Package.swift

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "BasicAuth",
5+
targets: [
6+
Target(name: "App"),
7+
Target(name: "Run", dependencies: ["App"]),
8+
],
9+
dependencies: [
10+
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
11+
.Package(url: "https://github.com/vapor/leaf-provider.git", majorVersion: 1),
12+
],
13+
exclude: [
14+
"Config",
15+
"Database",
16+
"Public",
17+
"Resources",
18+
]
19+
)
20+

Public/.gitkeep

Whitespace-only changes.

Public/images/it-works.png

8.31 KB
Loading

Public/styles/app.css

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
body, html {
2+
height: 100%;
3+
}
4+
5+
body {
6+
font-family: sans-serif;
7+
}
8+
9+
div.welcome {
10+
height: 100%;
11+
text-align: center;
12+
}
13+
14+
div.welcome img {
15+
position: relative;
16+
top: 50%;
17+
transform: translateY(-50%);
18+
width: 300px;
19+
}

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<p align="center">
2+
<img src="https://cloud.githubusercontent.com/assets/1977704/25426816/a9d40530-2a70-11e7-9758-8a0da6341035.png" width="320" alt="Web Template">
3+
<br>
4+
<br>
5+
<a href="https://docs.vapor.codes/2.0/getting-started/toolbox/#templates">
6+
<img src="http://img.shields.io/badge/read_the-docs-92A8D1.svg" alt="Documentation">
7+
</a>
8+
<a href="http://vapor.team">
9+
<img src="http://vapor.team/badge.svg" alt="Slack Team">
10+
</a>
11+
<a href="LICENSE">
12+
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
13+
</a>
14+
<a href="https://circleci.com/gh/vapor/web-template">
15+
<img src="https://circleci.com/gh/vapor/web-template.svg?style=shield" alt="Continuous Integration">
16+
</a>
17+
<a href="https://swift.org">
18+
<img src="http://img.shields.io/badge/swift-3.1-brightgreen.svg" alt="Swift 3.1">
19+
</a>
20+
</p>

Resources/Views/base.leaf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>#import("title")</title>
5+
<link rel="stylesheet" href="/styles/app.css">
6+
</head>
7+
<body>
8+
9+
#import("content")
10+
11+
</body>
12+
</html>

Resources/Views/hello.leaf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#extend("base")
2+
3+
#export("title") { Hello, #(name)! }
4+
5+
#export("content") {
6+
<h1>Hello, #(name)!</h1>
7+
}
8+

Resources/Views/welcome.leaf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#extend("base")
2+
3+
#export("title") { It works }
4+
5+
#export("content") {
6+
<div class="welcome">
7+
<img src="/images/it-works.png">
8+
</div>
9+
}
10+

Sources/App/Config+Setup.swift

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import LeafProvider
2+
3+
extension Config {
4+
public func setup() throws {
5+
// allow fuzzy conversions for these types
6+
// (add your own types here)
7+
Node.fuzzy = [JSON.self, Node.self]
8+
9+
try setupProviders()
10+
}
11+
12+
/// Configure providers
13+
private func setupProviders() throws {
14+
try addProvider(LeafProvider.Provider.self)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Vapor
2+
import HTTP
3+
4+
/// Here we have a controller that helps facilitate
5+
/// creating typical REST patterns
6+
final class HelloController: ResourceRepresentable {
7+
let view: ViewRenderer
8+
init(_ view: ViewRenderer) {
9+
self.view = view
10+
}
11+
12+
/// GET /hello
13+
func index(_ req: Request) throws -> ResponseRepresentable {
14+
return try view.make("hello", [
15+
"name": "World"
16+
], for: req)
17+
}
18+
19+
/// GET /hello/:string
20+
func show(_ req: Request, _ string: String) throws -> ResponseRepresentable {
21+
return try view.make("hello", [
22+
"name": string
23+
], for: req)
24+
}
25+
26+
/// When making a controller, it is pretty flexible in that it
27+
/// only expects closures, this is useful for advanced scenarios, but
28+
/// most of the time, it should look almost identical to this
29+
/// implementation
30+
func makeResource() -> Resource<String> {
31+
return Resource(
32+
index: index,
33+
show: show
34+
)
35+
}
36+
}

Sources/App/Droplet+Setup.swift

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@_exported import Vapor
2+
3+
extension Droplet {
4+
public func setup() throws {
5+
let routes = Routes(view)
6+
try collection(routes)
7+
}
8+
}

Sources/App/Models/.gitkeep

Whitespace-only changes.

Sources/App/Routes.swift

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Vapor
2+
3+
final class Routes: RouteCollection {
4+
let view: ViewRenderer
5+
init(_ view: ViewRenderer) {
6+
self.view = view
7+
}
8+
9+
func build(_ builder: RouteBuilder) throws {
10+
/// GET /
11+
builder.get { req in
12+
return try self.view.make("welcome")
13+
}
14+
15+
/// GET /hello/...
16+
builder.resource("hello", HelloController(view))
17+
18+
// response to requests to /info domain
19+
// with a description of the request
20+
builder.get("info") { req in
21+
return req.description
22+
}
23+
24+
}
25+
}

0 commit comments

Comments
 (0)