From df4b57896f2bbeaecab107b4ad26943b1a9d81ff Mon Sep 17 00:00:00 2001 From: Jayson Ng Date: Wed, 28 Jun 2023 16:22:44 +0800 Subject: [PATCH 1/5] Update Functions.swift Fix buildServerURL to check for default port 8081 --- Sources/ParseServerSwift/Utility/Functions.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/ParseServerSwift/Utility/Functions.swift b/Sources/ParseServerSwift/Utility/Functions.swift index 6e6da91b..d848d88e 100644 --- a/Sources/ParseServerSwift/Utility/Functions.swift +++ b/Sources/ParseServerSwift/Utility/Functions.swift @@ -144,9 +144,21 @@ public func getParseServerURLs(_ urls: String? = nil) throws -> (String, [String public func buildServerURL(from configuration: HTTPServer.Configuration) -> String { let scheme = configuration.tlsConfiguration == nil ? "http" : "https" let addressDescription: String + switch configuration.address { case .hostname(let hostname, let port): - addressDescription = "\(scheme)://\(hostname ?? configuration.hostname):\(port ?? configuration.port)" + + if port == 8081 { + switch configuration.hostname { + case "localhost", "127.0.0.1": + addressDescription = "\(scheme)://\(hostname ?? configuration.hostname):\(port ?? configuration.port)" + default: + addressDescription = "\(scheme)://\(hostname ?? configuration.hostname)" + } + } else { + addressDescription = "\(scheme)://\(hostname ?? configuration.hostname):\(port ?? configuration.port)" + } + case .unixDomainSocket(let socketPath): addressDescription = "\(scheme)+unix: \(socketPath)" } From 62adda75ba38e623ff73c18a687246ab43746055 Mon Sep 17 00:00:00 2001 From: Jayson Ng Date: Sat, 13 Jan 2024 14:33:53 +0800 Subject: [PATCH 2/5] Always use full path for Hook Triggers Adding fix from #41 to use with Hook Triggers as well. --- .../ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift b/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift index 49598450..bc5ec7de 100644 --- a/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift +++ b/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift @@ -1184,7 +1184,7 @@ public extension RoutesBuilder { let route = self.on(.POST, path, body: body, use: closure) Task { do { - await configuration.hooks.updateTriggers(try await ParseHookTrigger.create(path, + await configuration.hooks.updateTriggers(try await ParseHookTrigger.create(route.path, className: className, trigger: trigger)) } catch { From 8f1fe5dddf29df1ca5af180c75d3a88cce372c0d Mon Sep 17 00:00:00 2001 From: Jayson Ng Date: Sat, 13 Jan 2024 14:34:31 +0800 Subject: [PATCH 3/5] Fix some typos Just fixing some typos. --- README.md | 18 +++++++++--------- Sources/ParseServerSwift/routes.swift | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5e50d2d9..214c560e 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ Cloud Code Functions can also take parameters. It's recommended to place all par // A simple Parse Hook Function route that returns "Hello World". app.post("hello", name: "hello") { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "String" type. if let error: ParseHookResponse = checkHeaders(req) { return error @@ -297,7 +297,7 @@ app.post("hello", app.post("score", "save", "before", object: GameScore.self, trigger: .beforeSave) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "GameScore" type. if let error: ParseHookResponse = checkHeaders(req) { return error @@ -325,7 +325,7 @@ app.post("score", "save", "before", app.post("score", "find", "before", object: GameScore.self, trigger: .beforeFind) { req async throws -> ParseHookResponse<[GameScore]> in - // Note that `ParseHookResponse<[GameScore]>` means a "successfull" + // Note that `ParseHookResponse<[GameScore]>` means a "successful" // response will return a "[GameScore]" type. if let error: ParseHookResponse<[GameScore]> = checkHeaders(req) { return error @@ -352,7 +352,7 @@ app.post("score", "find", "before", app.post("user", "login", "after", object: User.self, trigger: .afterLogin) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -368,7 +368,7 @@ app.post("user", "login", "after", // A Parse Hook Trigger route for `ParseFile`. app.on("file", "save", "before", trigger: .beforeSave) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. Sending "false" // in this case will reject saving the file. @@ -385,7 +385,7 @@ app.on("file", "save", "before", // Another Parse Hook Trigger route for `ParseFile`. app.post("file", "delete", "before", trigger: .beforeDelete) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -401,7 +401,7 @@ app.post("file", "delete", "before", // A Parse Hook Trigger route for `ParseLiveQuery`. app.post("connect", "before", trigger: .beforeConnect) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -418,7 +418,7 @@ app.post("connect", "before", app.post("score", "subscribe", "before", object: GameScore.self, trigger: .beforeSubscribe) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -435,7 +435,7 @@ app.post("score", "subscribe", "before", app.post("score", "event", "after", object: GameScore.self, trigger: .afterEvent) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { diff --git a/Sources/ParseServerSwift/routes.swift b/Sources/ParseServerSwift/routes.swift index c0d304bc..f3aa047a 100644 --- a/Sources/ParseServerSwift/routes.swift +++ b/Sources/ParseServerSwift/routes.swift @@ -17,7 +17,7 @@ func routes(_ app: Application) throws { // A simple Parse Hook Function route that returns "Hello World". app.post("hello", name: "hello") { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "String" type. if let error: ParseHookResponse = checkHeaders(req) { return error @@ -41,7 +41,7 @@ func routes(_ app: Application) throws { // Another simple Parse Hook Function route that returns the version of the server. app.post("version", name: "version") { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "String" type. if let error: ParseHookResponse = checkHeaders(req) { return error @@ -92,7 +92,7 @@ func routes(_ app: Application) throws { app.post("score", "save", "before", object: GameScore.self, trigger: .beforeSave) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "GameScore" type. if let error: ParseHookResponse = checkHeaders(req) { return error @@ -120,7 +120,7 @@ func routes(_ app: Application) throws { app.post("score", "find", "before", object: GameScore.self, trigger: .beforeFind) { req async throws -> ParseHookResponse<[GameScore]> in - // Note that `ParseHookResponse<[GameScore]>` means a "successfull" + // Note that `ParseHookResponse<[GameScore]>` means a "successful" // response will return a "[GameScore]" type. if let error: ParseHookResponse<[GameScore]> = checkHeaders(req) { return error @@ -147,7 +147,7 @@ func routes(_ app: Application) throws { app.post("user", "login", "after", object: User.self, trigger: .afterLogin) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -163,7 +163,7 @@ func routes(_ app: Application) throws { // A Parse Hook Trigger route for `ParseFile`. app.on("file", "save", "before", trigger: .beforeSave) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. Sending "false" // in this case will reject saving the file. @@ -180,7 +180,7 @@ func routes(_ app: Application) throws { // Another Parse Hook Trigger route for `ParseFile`. app.post("file", "delete", "before", trigger: .beforeDelete) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -196,7 +196,7 @@ func routes(_ app: Application) throws { // A Parse Hook Trigger route for `ParseLiveQuery`. app.post("connect", "before", trigger: .beforeConnect) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -213,7 +213,7 @@ func routes(_ app: Application) throws { app.post("score", "subscribe", "before", object: GameScore.self, trigger: .beforeSubscribe) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { @@ -230,7 +230,7 @@ func routes(_ app: Application) throws { app.post("score", "event", "after", object: GameScore.self, trigger: .afterEvent) { req async throws -> ParseHookResponse in - // Note that `ParseHookResponse` means a "successfull" + // Note that `ParseHookResponse` means a "successful" // response will return a "Bool" type. Bool is the standard response with // a "true" response meaning everything is okay or continue. if let error: ParseHookResponse = checkHeaders(req) { From 42c55aa869ae36f79b1dcfc006cde4acb62f9df3 Mon Sep 17 00:00:00 2001 From: Jayson Ng Date: Sat, 13 Jan 2024 17:32:08 +0800 Subject: [PATCH 4/5] Update ParseHookTrigger+Vapor.swift Copy fix for #41 and apply it to ParseHookTrigger --- .../ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift b/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift index 49598450..bc5ec7de 100644 --- a/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift +++ b/Sources/ParseServerSwift/Extensions/ParseHookTrigger+Vapor.swift @@ -1184,7 +1184,7 @@ public extension RoutesBuilder { let route = self.on(.POST, path, body: body, use: closure) Task { do { - await configuration.hooks.updateTriggers(try await ParseHookTrigger.create(path, + await configuration.hooks.updateTriggers(try await ParseHookTrigger.create(route.path, className: className, trigger: trigger)) } catch { From 8305beac4a21486bf129836e4ff3e4803bf22340 Mon Sep 17 00:00:00 2001 From: Jayson Ng Date: Mon, 15 Jan 2024 01:59:57 +0800 Subject: [PATCH 5/5] Revert "Update Functions.swift" This reverts commit df4b57896f2bbeaecab107b4ad26943b1a9d81ff. --- Sources/ParseServerSwift/Utility/Functions.swift | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Sources/ParseServerSwift/Utility/Functions.swift b/Sources/ParseServerSwift/Utility/Functions.swift index d848d88e..6e6da91b 100644 --- a/Sources/ParseServerSwift/Utility/Functions.swift +++ b/Sources/ParseServerSwift/Utility/Functions.swift @@ -144,21 +144,9 @@ public func getParseServerURLs(_ urls: String? = nil) throws -> (String, [String public func buildServerURL(from configuration: HTTPServer.Configuration) -> String { let scheme = configuration.tlsConfiguration == nil ? "http" : "https" let addressDescription: String - switch configuration.address { case .hostname(let hostname, let port): - - if port == 8081 { - switch configuration.hostname { - case "localhost", "127.0.0.1": - addressDescription = "\(scheme)://\(hostname ?? configuration.hostname):\(port ?? configuration.port)" - default: - addressDescription = "\(scheme)://\(hostname ?? configuration.hostname)" - } - } else { - addressDescription = "\(scheme)://\(hostname ?? configuration.hostname):\(port ?? configuration.port)" - } - + addressDescription = "\(scheme)://\(hostname ?? configuration.hostname):\(port ?? configuration.port)" case .unixDomainSocket(let socketPath): addressDescription = "\(scheme)+unix: \(socketPath)" }