From 729af4d3ae8e0fd7e272770cc11614a3c946ae87 Mon Sep 17 00:00:00 2001 From: Matteo Date: Mon, 22 Aug 2016 00:44:51 +0200 Subject: [PATCH] first release --- .gitignore | 4 +++ .swift-version | 1 + Package.swift | 8 +++++ Sources/ToriAllowRemoteOrigin.swift | 32 +++++++++++++++++++ Tests/LinuxMain.swift | 6 ++++ .../ToriAllowRemoteOriginTests.swift | 17 ++++++++++ 6 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 .swift-version create mode 100644 Package.swift create mode 100644 Sources/ToriAllowRemoteOrigin.swift create mode 100644 Tests/LinuxMain.swift create mode 100644 Tests/ToriAllowRemoteOrigin/ToriAllowRemoteOriginTests.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1945f89 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.build +.vagrant +Packages +*.pkg diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..fbe576f --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +DEVELOPMENT-SNAPSHOT-2016-07-25-a diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..8db61ae --- /dev/null +++ b/Package.swift @@ -0,0 +1,8 @@ +import PackageDescription + +let package = Package( + name: "ToriAllowRemoteOrigin", + dependencies: [ + .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 26) + ] +) diff --git a/Sources/ToriAllowRemoteOrigin.swift b/Sources/ToriAllowRemoteOrigin.swift new file mode 100644 index 0000000..4c6c295 --- /dev/null +++ b/Sources/ToriAllowRemoteOrigin.swift @@ -0,0 +1,32 @@ +/** + * Copyright boostco.de 2016 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +import Foundation + +import Kitura + +private typealias AllowRemoteMiddlware = RouterMiddleware +class AllowRemoteOrigin: AllowRemoteMiddlware { + func handle(request: RouterRequest, response: RouterResponse, next: () -> Void) { + + // enable cors + response.headers.append("Access-Control-Allow-Origin", value: "*") + // set response to be only json formatted + response.headers.append("Content-Type", value: "application/json; charset=utf-8") + next() + + } +} diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..69694cd --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,6 @@ +import XCTest +@testable import ToriAllowRemoteOriginTestSuite + +XCTMain([ + testCase(ToriAllowRemoteOriginTests.allTests), +]) diff --git a/Tests/ToriAllowRemoteOrigin/ToriAllowRemoteOriginTests.swift b/Tests/ToriAllowRemoteOrigin/ToriAllowRemoteOriginTests.swift new file mode 100644 index 0000000..fa22082 --- /dev/null +++ b/Tests/ToriAllowRemoteOrigin/ToriAllowRemoteOriginTests.swift @@ -0,0 +1,17 @@ +import XCTest +@testable import ToriAllowRemoteOrigin + +class ToriAllowRemoteOriginTests: XCTestCase { + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + XCTAssertEqual(ToriAllowRemoteOrigin().text, "Hello, World!") + } + + + static var allTests : [(String, (ToriAllowRemoteOriginTests) -> () throws -> Void)] { + return [ + ("testExample", testExample), + ] + } +}