This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Service | |
#if os(Linux) | |
import Glibc | |
#else | |
import Darwin | |
#endif | |
extension Environment { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Dispatch | |
// Utility class for thread-safe access to an "app global" variable | |
final class DispatchBox<T>: Service { | |
private let queue = DispatchQueue(label: "DispatchBox_\(T.self)_Queue") | |
private var _value: T? | |
var value: T? { | |
get { return queue.sync { self._value }} | |
set { queue.async { self._value = newValue }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
#if os(Linux) | |
import Glibc | |
#else | |
import Darwin.C | |
#endif | |
final class SimpleRandom { | |
static func random(_ range: ClosedRange<Int32>) -> Int32 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let client = try req.make(Client.self) | |
let appKey = "APPKEY" // TODO: get from env | |
let masterSecret = "MASTERSECRET" // TODO: get from env | |
let broadcast = UABroadcast( | |
audience: .or([ | |
.channel(.ios, ["AAA", "BBB"]), | |
.channel(.android, ["CCC", "DDD", "EEE"]), | |
.tag("hello-tag", group: nil), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>No JS form example</title> | |
</head> | |
<body> | |
<form action="/form" method="post"> | |
#for(s in parts) { | |
<div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Vapor 3 port by @ajedwards | |
import Vapor | |
public final class ReactMiddleware: Middleware, ServiceType { | |
public static func makeService(for worker: Container) throws -> ReactMiddleware { | |
return try .init(defaultPath: worker.make(DirectoryConfig.self).workDir + "Public/index.html") | |
} | |
/// Default Path to index.html | |
/// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this file to your App target | |
import Fluent | |
import Vapor | |
import Dispatch | |
final class SingleDriver: Fluent.Driver, ConfigInitializable { | |
private let log: LogProtocol | |
private var backendDriver: Fluent.Driver | |
private let queue = DispatchQueue(label: "database-queue", qos: .utility) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leaf | |
import JSON | |
final class JSONPrint: BasicTag { | |
let name: String = "json" | |
func run(arguments: ArgumentList) throws -> Node? { | |
guard let arg = arguments.first else { | |
return nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vapor | |
import FluentProvider | |
import HTTP | |
import Foundation | |
final class Post: Model, Codable { | |
let storage = Storage() | |
// MARK: Properties and database keys | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Vapor | |
private enum UniversalCodingKey: CodingKey { | |
case int(Int) | |
case string(String) | |
init?(intValue: Int) { | |
self = .int(intValue) | |
} |