commit 931b897f65d48c293b419124f1f63719816b698a Author: Stephen Date: Thu Oct 31 16:50:33 2019 -0700 'created smparkinVaporWeb from template https://github.com/vapor/web-template' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c235f20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ + +# Created by https://www.gitignore.io/api/vapor + +### Vapor ### +Config/secrets + +### Vapor Patch ### +Packages +.build +xcuserdata +*.xcodeproj +DerivedData/ +.DS_Store + +# End of https://www.gitignore.io/api/vapor diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..fdadb43 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Contributing to Vapor Web Template + +If you found a mistake or think of a cool new feature, please [create an issue](https://github.com/vapor/web-template/issues/new) or, if you want to implement it yourself, [fork this repo](https://github.com/vapor/web-template/fork) and open a Pull Request! + +We'll take a look as soon as we can. + +Thanks! + +## Maintainers + +- [@0xTim](https://github.com/0xTim) + +See the [Vapor maintainers doc](https://github.com/vapor/vapor/blob/master/Docs/maintainers.md) for more information. diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..dae4bef --- /dev/null +++ b/Package.resolved @@ -0,0 +1,169 @@ +{ + "object": { + "pins": [ + { + "package": "Console", + "repositoryURL": "https://github.com/vapor/console.git", + "state": { + "branch": null, + "revision": "74cfbea629d4aac34a97cead2447a6870af1950b", + "version": "3.1.1" + } + }, + { + "package": "Core", + "repositoryURL": "https://github.com/vapor/core.git", + "state": { + "branch": null, + "revision": "57368d4092f92df3131e5968c8ed24a3c7361ec0", + "version": "3.8.1" + } + }, + { + "package": "Crypto", + "repositoryURL": "https://github.com/vapor/crypto.git", + "state": { + "branch": null, + "revision": "45bb12d13cdec80dbd1cc0685ea002e51ab83439", + "version": "3.3.2" + } + }, + { + "package": "DatabaseKit", + "repositoryURL": "https://github.com/vapor/database-kit.git", + "state": { + "branch": null, + "revision": "8f352c8e66dab301ab9bfef912a01ce1361ba1e4", + "version": "1.3.3" + } + }, + { + "package": "HTTP", + "repositoryURL": "https://github.com/vapor/http.git", + "state": { + "branch": null, + "revision": "254a0a0cbf22a02b697a075a0d2ddbb448bb7c87", + "version": "3.2.0" + } + }, + { + "package": "Leaf", + "repositoryURL": "https://github.com/vapor/leaf.git", + "state": { + "branch": null, + "revision": "d35f54cbac723e673f9bd5078361eea74049c8d7", + "version": "3.0.2" + } + }, + { + "package": "Multipart", + "repositoryURL": "https://github.com/vapor/multipart.git", + "state": { + "branch": null, + "revision": "f919a01c4d10a281d6236a21b0b1d1759a72b8eb", + "version": "3.0.4" + } + }, + { + "package": "Routing", + "repositoryURL": "https://github.com/vapor/routing.git", + "state": { + "branch": null, + "revision": "626190ddd2bd9f967743b60ba6adaf90bbd2651c", + "version": "3.0.2" + } + }, + { + "package": "Service", + "repositoryURL": "https://github.com/vapor/service.git", + "state": { + "branch": null, + "revision": "fa5b5de62bd68bcde9a69933f31319e46c7275fb", + "version": "1.0.2" + } + }, + { + "package": "swift-nio", + "repositoryURL": "https://github.com/apple/swift-nio.git", + "state": { + "branch": null, + "revision": "ba7970fe396e8198b84c6c1b44b38a1d4e2eb6bd", + "version": "1.14.1" + } + }, + { + "package": "swift-nio-ssl", + "repositoryURL": "https://github.com/apple/swift-nio-ssl.git", + "state": { + "branch": null, + "revision": "0f3999f3e3c359cc74480c292644c3419e44a12f", + "version": "1.4.0" + } + }, + { + "package": "swift-nio-ssl-support", + "repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git", + "state": { + "branch": null, + "revision": "c02eec4e0e6d351cd092938cf44195a8e669f555", + "version": "1.0.0" + } + }, + { + "package": "swift-nio-zlib-support", + "repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git", + "state": { + "branch": null, + "revision": "37760e9a52030bb9011972c5213c3350fa9d41fd", + "version": "1.0.0" + } + }, + { + "package": "TemplateKit", + "repositoryURL": "https://github.com/vapor/template-kit.git", + "state": { + "branch": null, + "revision": "4b1073d74be9f5c6a5bc63a07a84e83efec26229", + "version": "1.1.2" + } + }, + { + "package": "URLEncodedForm", + "repositoryURL": "https://github.com/vapor/url-encoded-form.git", + "state": { + "branch": null, + "revision": "82d8d63bdb76b6dd8febe916c639ab8608dbbaed", + "version": "1.0.6" + } + }, + { + "package": "Validation", + "repositoryURL": "https://github.com/vapor/validation.git", + "state": { + "branch": null, + "revision": "4de213cf319b694e4ce19e5339592601d4dd3ff6", + "version": "2.1.1" + } + }, + { + "package": "Vapor", + "repositoryURL": "https://github.com/vapor/vapor.git", + "state": { + "branch": null, + "revision": "c86ada59b31c69f08a6abd4f776537cba48d5df6", + "version": "3.3.0" + } + }, + { + "package": "WebSocket", + "repositoryURL": "https://github.com/vapor/websocket.git", + "state": { + "branch": null, + "revision": "d85e5b6dce4d04065865f77385fc3324f98178f6", + "version": "1.1.2" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e998791 --- /dev/null +++ b/Package.swift @@ -0,0 +1,19 @@ +// swift-tools-version:4.0 +import PackageDescription + +let package = Package( + name: "smparkinVaporWeb", + dependencies: [ + // 💧 A server-side Swift web framework. + .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"), + + // 🍃 An expressive, performant, and extensible templating language built for Swift. + .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0"), + ], + targets: [ + .target(name: "App", dependencies: ["Leaf", "Vapor"]), + .target(name: "Run", dependencies: ["App"]), + .testTarget(name: "AppTests", dependencies: ["App"]) + ] +) + diff --git a/Public/.gitkeep b/Public/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Public/images/it-works.png b/Public/images/it-works.png new file mode 100644 index 0000000..98d1102 Binary files /dev/null and b/Public/images/it-works.png differ diff --git a/Public/styles/app.css b/Public/styles/app.css new file mode 100644 index 0000000..c1e7a00 --- /dev/null +++ b/Public/styles/app.css @@ -0,0 +1,19 @@ +body, html { + height: 100%; +} + +body { + font-family: sans-serif; +} + +div.welcome { + height: 100%; + text-align: center; +} + +div.welcome img { + position: relative; + top: 50%; + transform: translateY(-50%); + width: 300px; +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..702888d --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +

+ Web Template +
+
+ + Documentation + + + Team Chat + + + MIT License + + + Continuous Integration + + + Swift 4.1 + +

diff --git a/Resources/Views/base.leaf b/Resources/Views/base.leaf new file mode 100644 index 0000000..80e43f8 --- /dev/null +++ b/Resources/Views/base.leaf @@ -0,0 +1,10 @@ + + + + #get(title) + + + + #get(body) + + diff --git a/Resources/Views/hello.leaf b/Resources/Views/hello.leaf new file mode 100644 index 0000000..422de5a --- /dev/null +++ b/Resources/Views/hello.leaf @@ -0,0 +1,7 @@ +#set("title") { Hello, #(name)! } + +#set("body") { +

Hello, #(name)!

+} + +#embed("base") diff --git a/Resources/Views/welcome.leaf b/Resources/Views/welcome.leaf new file mode 100644 index 0000000..6120b05 --- /dev/null +++ b/Resources/Views/welcome.leaf @@ -0,0 +1,9 @@ +#set("title") { It works } + +#set("body") { +
+ +
+} + +#embed("base") diff --git a/Sources/App/Controllers/.gitkeep b/Sources/App/Controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Sources/App/Models/.gitkeep b/Sources/App/Models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Sources/App/app.swift b/Sources/App/app.swift new file mode 100644 index 0000000..c1ecaaa --- /dev/null +++ b/Sources/App/app.swift @@ -0,0 +1,12 @@ +import Vapor + +/// Creates an instance of `Application`. This is called from `main.swift` in the run target. +public func app(_ env: Environment) throws -> Application { + var config = Config.default() + var env = env + var services = Services.default() + try configure(&config, &env, &services) + let app = try Application(config: config, environment: env, services: services) + try boot(app) + return app +} diff --git a/Sources/App/boot.swift b/Sources/App/boot.swift new file mode 100644 index 0000000..9313115 --- /dev/null +++ b/Sources/App/boot.swift @@ -0,0 +1,6 @@ +import Vapor + +/// Called after your application has initialized. +public func boot(_ app: Application) throws { + // Your code here +} diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift new file mode 100644 index 0000000..ce15d3c --- /dev/null +++ b/Sources/App/configure.swift @@ -0,0 +1,22 @@ +import Leaf +import Vapor + +/// Called before your application initializes. +public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws { + // Register providers first + try services.register(LeafProvider()) + + // Register routes to the router + let router = EngineRouter.default() + try routes(router) + services.register(router, as: Router.self) + + // Use Leaf for rendering views + config.prefer(LeafRenderer.self, for: ViewRenderer.self) + + // Register middleware + var middlewares = MiddlewareConfig() // Create _empty_ middleware config + middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory + middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response + services.register(middlewares) +} diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift new file mode 100644 index 0000000..399a140 --- /dev/null +++ b/Sources/App/routes.swift @@ -0,0 +1,16 @@ +import Vapor + +/// Register your application's routes here. +public func routes(_ router: Router) throws { + // "It works" page + router.get { req in + return try req.view().render("welcome") + } + + // Says hello + router.get("hello", String.parameter) { req -> Future in + return try req.view().render("hello", [ + "name": req.parameters.next(String.self) + ]) + } +} diff --git a/Sources/Run/main.swift b/Sources/Run/main.swift new file mode 100644 index 0000000..ade3aff --- /dev/null +++ b/Sources/Run/main.swift @@ -0,0 +1,3 @@ +import App + +try app(.detect()).run() diff --git a/Tests/AppTests/AppTests.swift b/Tests/AppTests/AppTests.swift new file mode 100644 index 0000000..d915e80 --- /dev/null +++ b/Tests/AppTests/AppTests.swift @@ -0,0 +1,12 @@ +import XCTest +@testable import App + +class AppTests: XCTestCase { + func testStub() throws { + XCTAssert(true) + } + + static let allTests = [ + ("testStub", testStub), + ] +} diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..f78cb77 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,11 @@ +#if os(Linux) + +import XCTest +@testable import AppTests + +XCTMain([ + // AppTests + testCase(AppTests.allTests), +]) + +#endif diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..583c382 --- /dev/null +++ b/circle.yml @@ -0,0 +1,43 @@ +version: 2 + +jobs: + linux: + docker: + - image: swift:4.1 + steps: + - checkout + - run: + name: Compile code + command: swift build + - run: + name: Run unit tests + command: swift test + + linux-release: + docker: + - image: swift:4.1 + steps: + - checkout + - run: + name: Compile code with optimizations + command: swift build -c release + +workflows: + version: 2 + tests: + jobs: + - linux + - linux-release + + nightly: + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - master + jobs: + - linux + - linux-release + \ No newline at end of file diff --git a/web.Dockerfile b/web.Dockerfile new file mode 100644 index 0000000..a778270 --- /dev/null +++ b/web.Dockerfile @@ -0,0 +1,30 @@ +# You can set the Swift version to what you need for your app. Versions can be found here: https://hub.docker.com/_/swift +FROM swift:5.0 as builder + +# For local build, add `--build-arg env=docker` +# In your application, you can use `Environment.custom(name: "docker")` to check if you're in this env +ARG env + +RUN apt-get -qq update && apt-get install -y \ + libssl-dev zlib1g-dev \ + && rm -r /var/lib/apt/lists/* +WORKDIR /app +COPY . . +RUN mkdir -p /build/lib && cp -R /usr/lib/swift/linux/*.so* /build/lib +RUN swift build -c release && mv `swift build -c release --show-bin-path` /build/bin + +# Production image +FROM ubuntu:18.04 +ARG env +# DEBIAN_FRONTEND=noninteractive for automatic UTC configuration in tzdata +RUN apt-get -qq update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + libatomic1 libicu60 libxml2 libcurl4 libz-dev libbsd0 tzdata \ + && rm -r /var/lib/apt/lists/* +WORKDIR /app +COPY --from=builder /build/bin/Run . +COPY --from=builder /build/lib/* /usr/lib/ +COPY --from=builder /app/Public ./Public +COPY --from=builder /app/Resources ./Resources +ENV ENVIRONMENT=$env + +ENTRYPOINT ./Run serve --env $ENVIRONMENT --hostname 0.0.0.0 --port 80