From 4d656931a87f0bda0f7b55c226e0dd29a21b6841 Mon Sep 17 00:00:00 2001 From: Viktoriia Kostyleva Date: Tue, 27 Sep 2022 15:40:13 +0300 Subject: [PATCH] #2: Run server --- .../project.pbxproj | 28 +++++++++++++ .../Common/Utilities/ClientConstants.swift | 15 +++++++ .../DVPNServer.swift | 39 +++++++++++++++++++ .../NodesRouteCollection.swift | 22 +++++++++++ .../ViewController.swift | 7 ++-- 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Common/Utilities/ClientConstants.swift create mode 100644 SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/DVPNServer.swift create mode 100644 SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/NodesRouteCollection.swift diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj index 8667032..aad414f 100644 --- a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj @@ -14,6 +14,9 @@ 92D6B40628E19E21004CF9DF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 92D6B40528E19E21004CF9DF /* Assets.xcassets */; }; 92D6B40928E19E21004CF9DF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 92D6B40728E19E21004CF9DF /* LaunchScreen.storyboard */; }; 92D6B41228E1D765004CF9DF /* Vapor in Frameworks */ = {isa = PBXBuildFile; productRef = 92D6B41128E1D765004CF9DF /* Vapor */; }; + 92D6B41428E1E133004CF9DF /* DVPNServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D6B41328E1E133004CF9DF /* DVPNServer.swift */; }; + 92D6B41828E2DC85004CF9DF /* NodesRouteCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D6B41728E2DC85004CF9DF /* NodesRouteCollection.swift */; }; + 92D6B41E28E2F64D004CF9DF /* ClientConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D6B41D28E2F64D004CF9DF /* ClientConstants.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -25,6 +28,9 @@ 92D6B40528E19E21004CF9DF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 92D6B40828E19E21004CF9DF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 92D6B40A28E19E21004CF9DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 92D6B41328E1E133004CF9DF /* DVPNServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DVPNServer.swift; sourceTree = ""; }; + 92D6B41728E2DC85004CF9DF /* NodesRouteCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodesRouteCollection.swift; sourceTree = ""; }; + 92D6B41D28E2F64D004CF9DF /* ClientConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientConstants.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,8 +64,11 @@ 92D6B3FB28E19E20004CF9DF /* SOLARdVPNCommunityCoreiOS */ = { isa = PBXGroup; children = ( + 92D6B41B28E2F62A004CF9DF /* Common */, 92D6B3FC28E19E20004CF9DF /* AppDelegate.swift */, 92D6B3FE28E19E20004CF9DF /* SceneDelegate.swift */, + 92D6B41328E1E133004CF9DF /* DVPNServer.swift */, + 92D6B41728E2DC85004CF9DF /* NodesRouteCollection.swift */, 92D6B40028E19E20004CF9DF /* ViewController.swift */, 92D6B40228E19E20004CF9DF /* Main.storyboard */, 92D6B40528E19E21004CF9DF /* Assets.xcassets */, @@ -69,6 +78,22 @@ path = SOLARdVPNCommunityCoreiOS; sourceTree = ""; }; + 92D6B41B28E2F62A004CF9DF /* Common */ = { + isa = PBXGroup; + children = ( + 92D6B41C28E2F63D004CF9DF /* Utilities */, + ); + path = Common; + sourceTree = ""; + }; + 92D6B41C28E2F63D004CF9DF /* Utilities */ = { + isa = PBXGroup; + children = ( + 92D6B41D28E2F64D004CF9DF /* ClientConstants.swift */, + ); + path = Utilities; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -147,7 +172,10 @@ buildActionMask = 2147483647; files = ( 92D6B40128E19E20004CF9DF /* ViewController.swift in Sources */, + 92D6B41828E2DC85004CF9DF /* NodesRouteCollection.swift in Sources */, 92D6B3FD28E19E20004CF9DF /* AppDelegate.swift in Sources */, + 92D6B41428E1E133004CF9DF /* DVPNServer.swift in Sources */, + 92D6B41E28E2F64D004CF9DF /* ClientConstants.swift in Sources */, 92D6B3FF28E19E20004CF9DF /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Common/Utilities/ClientConstants.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Common/Utilities/ClientConstants.swift new file mode 100644 index 0000000..f3c2c04 --- /dev/null +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Common/Utilities/ClientConstants.swift @@ -0,0 +1,15 @@ +// +// ClientConstants.swift +// SOLARdVPNCommunityCoreiOS +// +// Created by Viktoriia Kostyleva on 27.09.2022. +// + +import Foundation + +enum ClientConstants { + static let host = "localhost" + static let port = 3876 + + static let apiPath = "api" +} diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/DVPNServer.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/DVPNServer.swift new file mode 100644 index 0000000..e54908c --- /dev/null +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/DVPNServer.swift @@ -0,0 +1,39 @@ +// +// DVPNServer.swift +// SOLARdVPNCommunityCoreiOS +// +// Created by Viktoriia Kostyleva on 26.09.2022. +// + +import Vapor + +class DVPNServer: ObservableObject { + let app: Application + + init() { + app = Application(.development) + configure(app) + } +} + +extension DVPNServer { + func start() { + Task(priority: .background) { + do { + try app.register(collection: NodesRouteCollection()) + try app.start() + } catch { + fatalError(error.localizedDescription) + } + } + } +} + +// MARK: - Private + +extension DVPNServer { + private func configure(_ app: Application) { + app.http.server.configuration.hostname = ClientConstants.host + app.http.server.configuration.port = ClientConstants.port + } +} diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/NodesRouteCollection.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/NodesRouteCollection.swift new file mode 100644 index 0000000..1a8d012 --- /dev/null +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/NodesRouteCollection.swift @@ -0,0 +1,22 @@ +// +// NodesRouteCollection.swift +// SOLARdVPNCommunityCoreiOS +// +// Created by Viktoriia Kostyleva on 27.09.2022. +// + +import Vapor + +struct NodesRouteCollection: RouteCollection { + func boot(routes: RoutesBuilder) throws { + routes.get(use: getNodes) + routes.get(.init(stringLiteral: ClientConstants.apiPath), "nodes", use: getNodes) + } +} + +extension NodesRouteCollection { + func getNodes(_ req: Request) async throws -> Int { + + return 1 + } +} diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/ViewController.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/ViewController.swift index a776dae..e247b57 100644 --- a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/ViewController.swift +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/ViewController.swift @@ -8,12 +8,11 @@ import UIKit class ViewController: UIViewController { + let server = DVPNServer() override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. + + server.start() } - - } -