vapor app for running from ios

This commit is contained in:
2023-09-16 17:46:51 -07:00
parent e73f6e20ed
commit 26f4ed4fde
35 changed files with 665 additions and 241 deletions

3
.gitignore vendored
View File

@@ -1,3 +0,0 @@
.build*
.vscode*
.swiftpm*

View File

@@ -1,77 +0,0 @@
# ================================
# Build image
# ================================
FROM swift:5.7-jammy as build
# Install OS updates and, if needed, sqlite3
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y\
&& rm -rf /var/lib/apt/lists/*
# Set up a build area
WORKDIR /build
# First just resolve dependencies.
# This creates a cached layer that can be reused
# as long as your Package.swift/Package.resolved
# files do not change.
COPY ./Package.* ./
RUN swift package resolve
# Copy entire repo into container
COPY . .
# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib
# Switch to the staging area
WORKDIR /staging
# Copy main executable to staging area
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Run" ./
# Copy resources bundled by SPM to staging area
RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;
# Copy any resources from the public directory and views directory if the directories exist
# Ensure that by default, neither the directory nor any of its contents are writable.
RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
# ================================
# Run image
# ================================
FROM ubuntu:jammy
# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get -q install -y \
ca-certificates \
tzdata \
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
# libcurl4 \
# If your app or its dependencies import FoundationXML, also install `libxml2`.
# libxml2 \
&& rm -r /var/lib/apt/lists/*
# Create a vapor user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
# Switch to the new home directory
WORKDIR /app
# Copy built executable and any staged resources from builder
COPY --from=build --chown=vapor:vapor /staging /app
# Ensure all further commands run as the vapor user
USER vapor:vapor
# Let Docker bind to port 8080
EXPOSE 8080
# Start the Vapor service when the image is run, default to listening on 8080 in production environment
ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]

View File

@@ -1,40 +0,0 @@
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "smparkin",
platforms: [
.macOS(.v13),
.iOS(.v16)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/leaf.git", from: "4.0.0"),
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "Leaf", package: "leaf")
],
swiftSettings: [
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
]
),
.executableTarget(
name: "Run",
dependencies: [
.target(name: "App")
]
),
.testTarget(
name: "AppTests",
dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor")
]
)
]
)

View File

@@ -1 +0,0 @@
smpark.in

View File

@@ -1,15 +0,0 @@
import Leaf
import Vapor
// Called before your application initializes.
public func configure(_ app: Application) throws {
//leaf
app.views.use(.leaf)
//Register middleware
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.middleware.use(ErrorMiddleware.default(environment: app.environment))
//routes
try routes(app)
}

View File

@@ -1,9 +0,0 @@
import App
import Vapor
var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)
let app = Application(env)
defer { app.shutdown() }
try configure(app)
try app.run()

View File

@@ -1,12 +0,0 @@
import XCTest
@testable import App
class AppTests: XCTestCase {
func testStub() throws {
XCTAssert(true)
}
static let allTests = [
("testStub", testStub),
]
}

View File

@@ -1,11 +0,0 @@
#if os(Linux)
import XCTest
@testable import AppTests
XCTMain([
// AppTests
testCase(AppTests.allTests),
])
#endif

View File

@@ -1,30 +0,0 @@
# Docker Compose file for Vapor
#
# Install Docker on your system to run and test
# your Vapor app in a production-like environment.
#
# Note: This file is intended for testing and does not
# implement best practices for a production deployment.
#
# Learn more: https://docs.docker.com/compose/reference/
#
# Build images: docker-compose build
# Start app: docker-compose up app
# Stop all: docker-compose down
#
version: '3.7'
x-shared_environment: &shared_environment
LOG_LEVEL: ${LOG_LEVEL:-debug}
services:
app:
image: smparkin:latest
build:
context: .
environment:
<<: *shared_environment
ports:
- '8888:8888'
# user: '0' # uncomment to run as root for testing purposes even though Dockerfile defines 'vapor' user.
command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8888"]

View File

@@ -0,0 +1,439 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objects = {
/* Begin PBXBuildFile section */
C041F2C22AB021E30011752C /* smparkinApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C041F2C12AB021E30011752C /* smparkinApp.swift */; };
C041F2C42AB021E30011752C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C041F2C32AB021E30011752C /* ContentView.swift */; };
C041F2C62AB021E40011752C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C041F2C52AB021E40011752C /* Assets.xcassets */; };
C041F2C92AB021E40011752C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C041F2C82AB021E40011752C /* Preview Assets.xcassets */; };
C041F2D22AB0238F0011752C /* Vapor in Frameworks */ = {isa = PBXBuildFile; productRef = C041F2D12AB0238F0011752C /* Vapor */; };
C041F2D72AB023CA0011752C /* Leaf in Frameworks */ = {isa = PBXBuildFile; productRef = C041F2D62AB023CA0011752C /* Leaf */; };
C041F2DA2AB0243C0011752C /* Public in Resources */ = {isa = PBXBuildFile; fileRef = C041F2D82AB0243C0011752C /* Public */; };
C041F2DD2AB024510011752C /* Routes.swift in Sources */ = {isa = PBXBuildFile; fileRef = C041F2DC2AB024510011752C /* Routes.swift */; };
C041F2DF2AB0246C0011752C /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = C041F2DE2AB0246C0011752C /* Server.swift */; };
C0C8E2BE2AB0304D00E809B4 /* home.leaf in Resources */ = {isa = PBXBuildFile; fileRef = C0C8E2BB2AB02B6C00E809B4 /* home.leaf */; };
C0C8E2BF2AB0304D00E809B4 /* privacy.leaf in Resources */ = {isa = PBXBuildFile; fileRef = C0C8E2BC2AB02B6C00E809B4 /* privacy.leaf */; };
C0C8E2C02AB0304D00E809B4 /* welcome.leaf in Resources */ = {isa = PBXBuildFile; fileRef = C0C8E2BD2AB02B6C00E809B4 /* welcome.leaf */; };
C0C8E2C12AB0304D00E809B4 /* 404.leaf in Resources */ = {isa = PBXBuildFile; fileRef = C0C8E2BA2AB02B6C00E809B4 /* 404.leaf */; };
C0C8E2C52AB03D6200E809B4 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0C8E2C42AB03D6200E809B4 /* Log.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
C041F2BE2AB021E30011752C /* smparkin.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = smparkin.app; sourceTree = BUILT_PRODUCTS_DIR; };
C041F2C12AB021E30011752C /* smparkinApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = smparkinApp.swift; sourceTree = "<group>"; };
C041F2C32AB021E30011752C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
C041F2C52AB021E40011752C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C041F2C82AB021E40011752C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
C041F2D82AB0243C0011752C /* Public */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Public; sourceTree = "<group>"; };
C041F2DC2AB024510011752C /* Routes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Routes.swift; sourceTree = "<group>"; };
C041F2DE2AB0246C0011752C /* Server.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Server.swift; sourceTree = "<group>"; };
C0C8E2BA2AB02B6C00E809B4 /* 404.leaf */ = {isa = PBXFileReference; lastKnownFileType = text; path = 404.leaf; sourceTree = "<group>"; };
C0C8E2BB2AB02B6C00E809B4 /* home.leaf */ = {isa = PBXFileReference; lastKnownFileType = text; path = home.leaf; sourceTree = "<group>"; };
C0C8E2BC2AB02B6C00E809B4 /* privacy.leaf */ = {isa = PBXFileReference; lastKnownFileType = text; path = privacy.leaf; sourceTree = "<group>"; };
C0C8E2BD2AB02B6C00E809B4 /* welcome.leaf */ = {isa = PBXFileReference; lastKnownFileType = text; path = welcome.leaf; sourceTree = "<group>"; };
C0C8E2C42AB03D6200E809B4 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
C041F2BB2AB021E30011752C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C041F2D72AB023CA0011752C /* Leaf in Frameworks */,
C041F2D22AB0238F0011752C /* Vapor in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
C041F2B52AB021E30011752C = {
isa = PBXGroup;
children = (
C041F2C02AB021E30011752C /* smparkin */,
C041F2BF2AB021E30011752C /* Products */,
);
sourceTree = "<group>";
};
C041F2BF2AB021E30011752C /* Products */ = {
isa = PBXGroup;
children = (
C041F2BE2AB021E30011752C /* smparkin.app */,
);
name = Products;
sourceTree = "<group>";
};
C041F2C02AB021E30011752C /* smparkin */ = {
isa = PBXGroup;
children = (
C041F2C12AB021E30011752C /* smparkinApp.swift */,
C041F2C32AB021E30011752C /* ContentView.swift */,
C041F2DE2AB0246C0011752C /* Server.swift */,
C041F2DC2AB024510011752C /* Routes.swift */,
C0C8E2C42AB03D6200E809B4 /* Log.swift */,
C0C8E2B92AB02B6C00E809B4 /* Views */,
C041F2D82AB0243C0011752C /* Public */,
C041F2C52AB021E40011752C /* Assets.xcassets */,
C041F2C72AB021E40011752C /* Preview Content */,
);
path = smparkin;
sourceTree = "<group>";
};
C041F2C72AB021E40011752C /* Preview Content */ = {
isa = PBXGroup;
children = (
C041F2C82AB021E40011752C /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
C0C8E2B92AB02B6C00E809B4 /* Views */ = {
isa = PBXGroup;
children = (
C0C8E2BA2AB02B6C00E809B4 /* 404.leaf */,
C0C8E2BB2AB02B6C00E809B4 /* home.leaf */,
C0C8E2BC2AB02B6C00E809B4 /* privacy.leaf */,
C0C8E2BD2AB02B6C00E809B4 /* welcome.leaf */,
);
path = Views;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
C041F2BD2AB021E30011752C /* smparkin */ = {
isa = PBXNativeTarget;
buildConfigurationList = C041F2CC2AB021E40011752C /* Build configuration list for PBXNativeTarget "smparkin" */;
buildPhases = (
C041F2BA2AB021E30011752C /* Sources */,
C041F2BB2AB021E30011752C /* Frameworks */,
C041F2BC2AB021E30011752C /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = smparkin;
packageProductDependencies = (
C041F2D12AB0238F0011752C /* Vapor */,
C041F2D62AB023CA0011752C /* Leaf */,
);
productName = smparkin;
productReference = C041F2BE2AB021E30011752C /* smparkin.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
C041F2B62AB021E30011752C /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
TargetAttributes = {
C041F2BD2AB021E30011752C = {
CreatedOnToolsVersion = 15.0;
};
};
};
buildConfigurationList = C041F2B92AB021E30011752C /* Build configuration list for PBXProject "smparkin" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = C041F2B52AB021E30011752C;
packageReferences = (
C041F2D02AB0238F0011752C /* XCRemoteSwiftPackageReference "vapor" */,
C041F2D52AB023CA0011752C /* XCRemoteSwiftPackageReference "leaf" */,
);
productRefGroup = C041F2BF2AB021E30011752C /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
C041F2BD2AB021E30011752C /* smparkin */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
C041F2BC2AB021E30011752C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C0C8E2BE2AB0304D00E809B4 /* home.leaf in Resources */,
C0C8E2C12AB0304D00E809B4 /* 404.leaf in Resources */,
C041F2C92AB021E40011752C /* Preview Assets.xcassets in Resources */,
C041F2DA2AB0243C0011752C /* Public in Resources */,
C041F2C62AB021E40011752C /* Assets.xcassets in Resources */,
C0C8E2C02AB0304D00E809B4 /* welcome.leaf in Resources */,
C0C8E2BF2AB0304D00E809B4 /* privacy.leaf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
C041F2BA2AB021E30011752C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C041F2DF2AB0246C0011752C /* Server.swift in Sources */,
C041F2C42AB021E30011752C /* ContentView.swift in Sources */,
C0C8E2C52AB03D6200E809B4 /* Log.swift in Sources */,
C041F2C22AB021E30011752C /* smparkinApp.swift in Sources */,
C041F2DD2AB024510011752C /* Routes.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
C041F2CA2AB021E40011752C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
C041F2CB2AB021E40011752C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
C041F2CD2AB021E40011752C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"smparkin/Preview Content\"";
DEVELOPMENT_TEAM = QR825BQSTL;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = in.smpark.smparkin;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
C041F2CE2AB021E40011752C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"smparkin/Preview Content\"";
DEVELOPMENT_TEAM = QR825BQSTL;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = in.smpark.smparkin;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
C041F2B92AB021E30011752C /* Build configuration list for PBXProject "smparkin" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C041F2CA2AB021E40011752C /* Debug */,
C041F2CB2AB021E40011752C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C041F2CC2AB021E40011752C /* Build configuration list for PBXNativeTarget "smparkin" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C041F2CD2AB021E40011752C /* Debug */,
C041F2CE2AB021E40011752C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
C041F2D02AB0238F0011752C /* XCRemoteSwiftPackageReference "vapor" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/vapor/vapor.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.81.0;
};
};
C041F2D52AB023CA0011752C /* XCRemoteSwiftPackageReference "leaf" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/vapor/leaf.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.2.4;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
C041F2D12AB0238F0011752C /* Vapor */ = {
isa = XCSwiftPackageProductDependency;
package = C041F2D02AB0238F0011752C /* XCRemoteSwiftPackageReference "vapor" */;
productName = Vapor;
};
C041F2D62AB023CA0011752C /* Leaf */ = {
isa = XCSwiftPackageProductDependency;
package = C041F2D52AB023CA0011752C /* XCRemoteSwiftPackageReference "leaf" */;
productName = Leaf;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = C041F2B62AB021E30011752C /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "864c8d9e0ead5de7ba70b61c8982f89126710863",
"version" : "1.15.0"
"revision" : "16f7e62c08c6969899ce6cc277041e868364e5cf",
"version" : "1.19.0"
}
},
{
@@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/async-kit.git",
"state" : {
"revision" : "9acea4c92f51a5885c149904f0d11db4712dda80",
"version" : "1.16.0"
"revision" : "eab9edff78e8ace20bd7cb6e792ab46d54f59ab9",
"version" : "1.18.0"
}
},
{
@@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/console-kit.git",
"state" : {
"revision" : "447f1046fb4e9df40973fe426ecb24a6f0e8d3b4",
"version" : "4.6.0"
"revision" : "9a12000f4064a2bdc49068d7258292ec1bdc88fc",
"version" : "4.7.0"
}
},
{
@@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/leaf-kit.git",
"state" : {
"revision" : "62169b44cc79734e11bf44b8d7154865dee5936b",
"version" : "1.10.1"
"revision" : "13f2fc4c8479113cd23876d9a434ef4573e368bb",
"version" : "1.10.2"
}
},
{
@@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/multipart-kit.git",
"state" : {
"revision" : "0d55c35e788451ee27222783c7d363cb88092fab",
"version" : "4.5.2"
"revision" : "1adfd69df2da08f7931d4281b257475e32c96734",
"version" : "4.5.4"
}
},
{
@@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/routing-kit.git",
"state" : {
"revision" : "ffac7b3a127ce1e85fb232f1a6271164628809ad",
"version" : "4.6.0"
"revision" : "e0539da5b60a60d7381f44cdcf04036f456cee2f",
"version" : "4.8.0"
}
},
{
@@ -77,17 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036",
"version" : "1.0.3"
}
},
{
"identity" : "swift-backtrace",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-backtrace.git",
"state" : {
"revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956",
"version" : "1.3.3"
"revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10",
"version" : "1.1.0"
}
},
{
@@ -104,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "da0fe44138ab86e380f40a2acbd8a611b07d3f64",
"version" : "2.4.0"
"revision" : "60f13f60c4d093691934dc6cfdf5f508ada1f894",
"version" : "2.6.0"
}
},
{
@@ -113,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
"version" : "1.5.2"
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
}
},
{
@@ -122,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "e8bced74bc6d747745935e469f45d03f048d6cbd",
"version" : "2.3.4"
"revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1",
"version" : "2.4.1"
}
},
{
@@ -131,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "45167b8006448c79dda4b7bd604e07a034c15c49",
"version" : "2.48.0"
"revision" : "cf281631ff10ec6111f2761052aa81896a83a007",
"version" : "2.58.0"
}
},
{
@@ -140,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "d75ed708d00353acf173ca23018b6bd46f949464",
"version" : "1.17.0"
"revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997",
"version" : "1.19.0"
}
},
{
@@ -149,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "38feec96bcd929028939107684073554bf01abeb",
"version" : "1.25.2"
"revision" : "a8ccf13fa62775277a5d56844878c828bbb3be1a",
"version" : "1.27.0"
}
},
{
@@ -158,8 +149,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3",
"version" : "2.23.0"
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
}
},
{
@@ -167,8 +158,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c",
"version" : "1.15.0"
"revision" : "e7403c35ca6bb539a7ca353b91cc2d8ec0362d58",
"version" : "1.19.0"
}
},
{
@@ -185,8 +176,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/vapor.git",
"state" : {
"revision" : "bac0fe31e3b186537eb750d44fae048681e2b773",
"version" : "4.74.0"
"revision" : "03a08f6e88d5ca8c1cfd84f8367b21dfe050d082",
"version" : "4.81.0"
}
},
{
@@ -194,8 +185,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "2b8885974e8d9f522e787805000553f4f7cce8a0",
"version" : "2.7.0"
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
"version" : "2.14.0"
}
}
],

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>smparkin.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,29 @@
//
// ContentView.swift
// smparkin
//
// Created by Stephen Parkinson on 9/11/23.
//
import SwiftUI
struct ContentView: View {
@StateObject var server: Server = Server(port: 8080)
var body: some View {
VStack {
Text(ProcessInfo().hostName + ":\(server.port)")
List(server.logs.reversed(), id: \.self) { log in
Text(log)
}
}
.padding()
.onAppear {
server.start()
}
}
}
#Preview {
ContentView()
}

23
smparkin/Log.swift Normal file
View File

@@ -0,0 +1,23 @@
//
// Log.swift
// smparkin
//
// Created by Stephen Parkinson on 9/11/23.
//
import Vapor
struct LogMiddleware: Middleware {
let server: Server
init(server: Server) {
self.server = server
}
func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
DispatchQueue.main.async {
server.logs.append("\(server.dateFormatter.string(from: Date.now)) \(request.url.path)")
}
return next.respond(to: request)
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

Before

Width:  |  Height:  |  Size: 497 KiB

After

Width:  |  Height:  |  Size: 497 KiB

View File

Before

Width:  |  Height:  |  Size: 544 KiB

After

Width:  |  Height:  |  Size: 544 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

Before

Width:  |  Height:  |  Size: 466 KiB

After

Width:  |  Height:  |  Size: 466 KiB

58
smparkin/Server.swift Normal file
View File

@@ -0,0 +1,58 @@
import Leaf
import Vapor
import SwiftUI
class Server: ObservableObject {
@Published var logs: [String] = [String]()
let dateFormatter = ISO8601DateFormatter()
var app: Application
let port: Int
init(port: Int) {
self.port = port
app = Application(.production)
configure(app)
}
// Called before your application initializes.
private func configure(_ app: Application) {
app.http.server.configuration.hostname = "0.0.0.0"
app.http.server.configuration.port = port
//leaf
app.views.use(.leaf)
app.leaf.cache.isEnabled = app.environment.isRelease
app.leaf.configuration.rootDirectory = Bundle.main.bundlePath
//Register middleware
app.middleware.use(FileMiddleware(publicDirectory: "\(Bundle.main.bundlePath)/\(app.directory.publicDirectory)"))
app.middleware.use(ErrorMiddleware.default(environment: app.environment))
app.middleware.use(LogMiddleware.init(server: self))
//routes
do {
try routes(app)
} catch {
fatalError(error.localizedDescription)
}
}
func start() {
Task(priority: .background) {
do {
try app.start()
} catch {
fatalError(error.localizedDescription)
}
}
}
func stop() {
app.shutdown()
}
func restart() {
stop()
start()
}
}

View File

@@ -0,0 +1,17 @@
//
// smparkinApp.swift
// smparkin
//
// Created by Stephen Parkinson on 9/11/23.
//
import SwiftUI
@main
struct smparkinApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}