on master help sign in
'created WSExample1 from template https://github.com/vapor/api-template'
c3c3690ilyakooo0
.circleci/config.ymlnew file+43
@@ -0,0 +1,43 @@
1+version: 2
2+
3+jobs:
4+ linux:
5+ docker:
6+ - image: swift:4.1
7+ steps:
8+ - checkout
9+ - run:
10+ name: Compile code
11+ command: swift build
12+ - run:
13+ name: Run unit tests
14+ command: swift test
15+
16+ linux-release:
17+ docker:
18+ - image: swift:4.1
19+ steps:
20+ - checkout
21+ - run:
22+ name: Compile code with optimizations
23+ command: swift build -c release
24+
25+workflows:
26+ version: 2
27+ tests:
28+ jobs:
29+ - linux
30+ - linux-release
31+
32+ nightly:
33+ triggers:
34+ - schedule:
35+ cron: "0 0 * * *"
36+ filters:
37+ branches:
38+ only:
39+ - master
40+ jobs:
41+ - linux
42+ - linux-release
43+
.dockerignorenew file+6
@@ -0,0 +1,6 @@
1+.git
2+.build
3+DerivedData
4+Package.resolved
5+*.xcodeproj
6+
.gitignorenew file+6
@@ -0,0 +1,6 @@
1+Packages
2+.build
3+xcuserdata
4+*.xcodeproj
5+DerivedData/
6+.DS_Store
Package.resolvednew file+196
@@ -0,0 +1,196 @@
1+{
2+ "object": {
3+ "pins": [
4+ {
5+ "package": "Console",
6+ "repositoryURL": "https://github.com/vapor/console.git",
7+ "state": {
8+ "branch": null,
9+ "revision": "5b9796d39f201b3dd06800437abd9d774a455e57",
10+ "version": "3.0.2"
11+ }
12+ },
13+ {
14+ "package": "Core",
15+ "repositoryURL": "https://github.com/vapor/core.git",
16+ "state": {
17+ "branch": null,
18+ "revision": "eb876a758733166a4fb20f3f0a17b480c5ea563e",
19+ "version": "3.4.3"
20+ }
21+ },
22+ {
23+ "package": "Crypto",
24+ "repositoryURL": "https://github.com/vapor/crypto.git",
25+ "state": {
26+ "branch": null,
27+ "revision": "5605334590affd4785a5839806b4504407e054ac",
28+ "version": "3.3.0"
29+ }
30+ },
31+ {
32+ "package": "DatabaseKit",
33+ "repositoryURL": "https://github.com/vapor/database-kit.git",
34+ "state": {
35+ "branch": null,
36+ "revision": "3a17dbbe9be5f8c37703e4b7982c1332ad6b00c4",
37+ "version": "1.3.1"
38+ }
39+ },
40+ {
41+ "package": "Fluent",
42+ "repositoryURL": "https://github.com/vapor/fluent.git",
43+ "state": {
44+ "branch": null,
45+ "revision": "270b6fa372f03809b9795e8f8b9d1c31267a0ff3",
46+ "version": "3.0.0"
47+ }
48+ },
49+ {
50+ "package": "FluentSQLite",
51+ "repositoryURL": "https://github.com/vapor/fluent-sqlite.git",
52+ "state": {
53+ "branch": null,
54+ "revision": "c32f5bda84bf4ea691d19afe183d40044f579e11",
55+ "version": "3.0.0"
56+ }
57+ },
58+ {
59+ "package": "HTTP",
60+ "repositoryURL": "https://github.com/vapor/http.git",
61+ "state": {
62+ "branch": null,
63+ "revision": "272b22be8cb3364e42a4701c2e0676e37480ec5a",
64+ "version": "3.1.5"
65+ }
66+ },
67+ {
68+ "package": "Multipart",
69+ "repositoryURL": "https://github.com/vapor/multipart.git",
70+ "state": {
71+ "branch": null,
72+ "revision": "e57007c23a52b68e44ebdfc70cbe882a7c4f1ec3",
73+ "version": "3.0.2"
74+ }
75+ },
76+ {
77+ "package": "Routing",
78+ "repositoryURL": "https://github.com/vapor/routing.git",
79+ "state": {
80+ "branch": null,
81+ "revision": "3219e328491b0853b8554c5a694add344d2c6cfb",
82+ "version": "3.0.1"
83+ }
84+ },
85+ {
86+ "package": "Service",
87+ "repositoryURL": "https://github.com/vapor/service.git",
88+ "state": {
89+ "branch": null,
90+ "revision": "281a70b69783891900be31a9e70051b6fe19e146",
91+ "version": "1.0.0"
92+ }
93+ },
94+ {
95+ "package": "SQL",
96+ "repositoryURL": "https://github.com/vapor/sql.git",
97+ "state": {
98+ "branch": null,
99+ "revision": "a35cf1dced4ddd32bb2dc8b6e765aea7bcf8d6e0",
100+ "version": "2.1.0"
101+ }
102+ },
103+ {
104+ "package": "SQLite",
105+ "repositoryURL": "https://github.com/vapor/sqlite.git",
106+ "state": {
107+ "branch": null,
108+ "revision": "ad2e9bc9f0ed00ef2c6a05f89c1cec605467c90f",
109+ "version": "3.1.0"
110+ }
111+ },
112+ {
113+ "package": "swift-nio",
114+ "repositoryURL": "https://github.com/apple/swift-nio.git",
115+ "state": {
116+ "branch": null,
117+ "revision": "5d8148c8b45dfb449276557f22120694567dd1d2",
118+ "version": "1.9.5"
119+ }
120+ },
121+ {
122+ "package": "swift-nio-ssl",
123+ "repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
124+ "state": {
125+ "branch": null,
126+ "revision": "8380fa29a2af784b067d8ee01c956626ca29f172",
127+ "version": "1.3.1"
128+ }
129+ },
130+ {
131+ "package": "swift-nio-ssl-support",
132+ "repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
133+ "state": {
134+ "branch": null,
135+ "revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
136+ "version": "1.0.0"
137+ }
138+ },
139+ {
140+ "package": "swift-nio-zlib-support",
141+ "repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
142+ "state": {
143+ "branch": null,
144+ "revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
145+ "version": "1.0.0"
146+ }
147+ },
148+ {
149+ "package": "TemplateKit",
150+ "repositoryURL": "https://github.com/vapor/template-kit.git",
151+ "state": {
152+ "branch": null,
153+ "revision": "db35b1c35aabd0f5db3abca0cfda7becfe9c43e2",
154+ "version": "1.1.0"
155+ }
156+ },
157+ {
158+ "package": "URLEncodedForm",
159+ "repositoryURL": "https://github.com/vapor/url-encoded-form.git",
160+ "state": {
161+ "branch": null,
162+ "revision": "932024f363ee5ff59059cf7d67194a1c271d3d0c",
163+ "version": "1.0.5"
164+ }
165+ },
166+ {
167+ "package": "Validation",
168+ "repositoryURL": "https://github.com/vapor/validation.git",
169+ "state": {
170+ "branch": null,
171+ "revision": "156f8adeac3440e868da3757777884efbc6ec0cc",
172+ "version": "2.1.0"
173+ }
174+ },
175+ {
176+ "package": "Vapor",
177+ "repositoryURL": "https://github.com/vapor/vapor.git",
178+ "state": {
179+ "branch": null,
180+ "revision": "157d3b15336caa882662cc75024dd04b2e225246",
181+ "version": "3.1.0"
182+ }
183+ },
184+ {
185+ "package": "WebSocket",
186+ "repositoryURL": "https://github.com/vapor/websocket.git",
187+ "state": {
188+ "branch": null,
189+ "revision": "149af03348f60ac8b84defdf277112d62fd8c704",
190+ "version": "1.0.2"
191+ }
192+ }
193+ ]
194+ },
195+ "version": 1
196+}
Package.swiftnew file+19
@@ -0,0 +1,19 @@
1+// swift-tools-version:4.0
2+import PackageDescription
3+
4+let package = Package(
5+ name: "WSExample1",
6+ dependencies: [
7+ // 💧 A server-side Swift web framework.
8+ .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
9+
10+ // 🔵 Swift ORM (queries, models, relations, etc) built on SQLite 3.
11+ .package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0")
12+ ],
13+ targets: [
14+ .target(name: "App", dependencies: ["FluentSQLite", "Vapor"]),
15+ .target(name: "Run", dependencies: ["App"]),
16+ .testTarget(name: "AppTests", dependencies: ["App"])
17+ ]
18+)
19+
Public/.gitkeepnew file

No changes to the content.

README.mdnew file+20
@@ -0,0 +1,20 @@
1+<p align="center">
2+ <img src="https://user-images.githubusercontent.com/1342803/36623515-7293b4ec-18d3-11e8-85ab-4e2f8fb38fbd.png" width="320" alt="API Template">
3+ <br>
4+ <br>
5+ <a href="http://docs.vapor.codes/3.0/">
6+ <img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
7+ </a>
8+ <a href="https://discord.gg/vapor">
9+ <img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
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/api-template">
15+ <img src="https://circleci.com/gh/vapor/api-template.svg?style=shield" alt="Continuous Integration">
16+ </a>
17+ <a href="https://swift.org">
18+ <img src="http://img.shields.io/badge/swift-4.1-brightgreen.svg" alt="Swift 4.1">
19+ </a>
20+</p>
Sources/App/Controllers/.gitkeepnew file

No changes to the content.

Sources/App/Controllers/TodoController.swiftnew file+23
@@ -0,0 +1,23 @@
1+import Vapor
2+
3+/// Controls basic CRUD operations on `Todo`s.
4+final class TodoController {
5+ /// Returns a list of all `Todo`s.
6+ func index(_ req: Request) throws -> Future<[Todo]> {
7+ return Todo.query(on: req).all()
8+ }
9+
10+ /// Saves a decoded `Todo` to the database.
11+ func create(_ req: Request) throws -> Future<Todo> {
12+ return try req.content.decode(Todo.self).flatMap { todo in
13+ return todo.save(on: req)
14+ }
15+ }
16+
17+ /// Deletes a parameterized `Todo`.
18+ func delete(_ req: Request) throws -> Future<HTTPStatus> {
19+ return try req.parameters.next(Todo.self).flatMap { todo in
20+ return todo.delete(on: req)
21+ }.transform(to: .ok)
22+ }
23+}
Sources/App/Models/.gitkeepnew file

No changes to the content.

Sources/App/Models/Todo.swiftnew file+26
@@ -0,0 +1,26 @@
1+import FluentSQLite
2+import Vapor
3+
4+/// A single entry of a Todo list.
5+final class Todo: SQLiteModel {
6+ /// The unique identifier for this `Todo`.
7+ var id: Int?
8+
9+ /// A title describing what this `Todo` entails.
10+ var title: String
11+
12+ /// Creates a new `Todo`.
13+ init(id: Int? = nil, title: String) {
14+ self.id = id
15+ self.title = title
16+ }
17+}
18+
19+/// Allows `Todo` to be used as a dynamic migration.
20+extension Todo: Migration { }
21+
22+/// Allows `Todo` to be encoded to and decoded from HTTP messages.
23+extension Todo: Content { }
24+
25+/// Allows `Todo` to be used as a dynamic parameter in route definitions.
26+extension Todo: Parameter { }
Sources/App/app.swiftnew file+12
@@ -0,0 +1,12 @@
1+import Vapor
2+
3+/// Creates an instance of Application. This is called from main.swift in the run target.
4+public func app(_ env: Environment) throws -> Application {
5+ var config = Config.default()
6+ var env = env
7+ var services = Services.default()
8+ try configure(&config, &env, &services)
9+ let app = try Application(config: config, environment: env, services: services)
10+ try boot(app)
11+ return app
12+}
Sources/App/boot.swiftnew file+6
@@ -0,0 +1,6 @@
1+import Vapor
2+
3+/// Called after your application has initialized.
4+public func boot(_ app: Application) throws {
5+ // your code here
6+}
Sources/App/configure.swiftnew file+33
@@ -0,0 +1,33 @@
1+import FluentSQLite
2+import Vapor
3+
4+/// Called before your application initializes.
5+public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
6+ /// Register providers first
7+ try services.register(FluentSQLiteProvider())
8+
9+ /// Register routes to the router
10+ let router = EngineRouter.default()
11+ try routes(router)
12+ services.register(router, as: Router.self)
13+
14+ /// Register middleware
15+ var middlewares = MiddlewareConfig() // Create _empty_ middleware config
16+ /// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
17+ middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
18+ services.register(middlewares)
19+
20+ // Configure a SQLite database
21+ let sqlite = try SQLiteDatabase(storage: .memory)
22+
23+ /// Register the configured SQLite database to the database config.
24+ var databases = DatabasesConfig()
25+ databases.add(database: sqlite, as: .sqlite)
26+ services.register(databases)
27+
28+ /// Configure migrations
29+ var migrations = MigrationConfig()
30+ migrations.add(model: Todo.self, database: .sqlite)
31+ services.register(migrations)
32+
33+}
Sources/App/routes.swiftnew file+20
@@ -0,0 +1,20 @@
1+import Vapor
2+
3+/// Register your application's routes here.
4+public func routes(_ router: Router) throws {
5+ // Basic "It works" example
6+ router.get { req in
7+ return "It works!"
8+ }
9+
10+ // Basic "Hello, world!" example
11+ router.get("hello") { req in
12+ return "Hello, world!"
13+ }
14+
15+ // Example of configuring a controller
16+ let todoController = TodoController()
17+ router.get("todos", use: todoController.index)
18+ router.post("todos", use: todoController.create)
19+ router.delete("todos", Todo.parameter, use: todoController.delete)
20+}
Sources/Run/main.swiftnew file+3
@@ -0,0 +1,3 @@
1+import App
2+
3+try app(.detect()).run()
Tests/.gitkeepnew file

No changes to the content.

Tests/AppTests/AppTests.swiftnew file+13
@@ -0,0 +1,13 @@
1+import App
2+import XCTest
3+
4+final class AppTests: XCTestCase {
5+ func testNothing() throws {
6+ // add your tests here
7+ XCTAssert(true)
8+ }
9+
10+ static let allTests = [
11+ ("testNothing", testNothing)
12+ ]
13+}
Tests/LinuxMain.swiftnew file

No changes to the content.

cloud.ymlnew file+3
@@ -0,0 +1,3 @@
1+type: "vapor"
2+swift_version: "4.1.0"
3+run_parameters: "serve --port 8080 --hostname 0.0.0.0"
web.Dockerfilenew file+29
@@ -0,0 +1,29 @@
1+# You can set the Swift version to what you need for your app. Versions can be found here: https://hub.docker.com/_/swift
2+FROM swift:4.2 as builder
3+
4+# For local build, add `--build-arg environment=local`
5+ARG env=""
6+ENV ENVIRONMENT=$env
7+
8+RUN apt-get -qq update && apt-get -q -y install \
9+ tzdata \
10+ && rm -r /var/lib/apt/lists/*
11+WORKDIR /app
12+COPY . .
13+RUN mkdir -p /build/lib && cp -R /usr/lib/swift/linux/*.so /build/lib
14+RUN swift build -c release && mv `swift build -c release --show-bin-path` /build/bin
15+
16+# Production image
17+FROM ubuntu:16.04
18+RUN apt-get -qq update && apt-get install -y \
19+ libicu55 libxml2 libbsd0 libcurl3 libatomic1 \
20+ tzdata \
21+ && rm -r /var/lib/apt/lists/*
22+WORKDIR /app
23+COPY --from=builder /build/bin/Run .
24+COPY --from=builder /build/lib/* /usr/lib/
25+COPY --from=builder /app/Public ./Public
26+# Uncommand the next line if you are using Leaf
27+#COPY --from=builder /app/Resources ./Resources
28+
29+ENTRYPOINT ./Run serve --env $ENVIRONMENT --hostname 0.0.0.0 --port 80