ferno icon indicating copy to clipboard operation
ferno copied to clipboard

[WIP] Update to Vapor4

Open maximkrouk opened this issue 4 years ago • 11 comments

Not sure if the architecture I implemented actually fits Vapor4 enough, so I think some code review would be appreciated 🙂

Readme is related to my personal account and I'll fix it after the review, that's why this PR has WIP label

maximkrouk avatar Jun 15 '20 18:06 maximkrouk

any shot we could get this merged?

Steven4294 avatar Jul 27 '20 01:07 Steven4294

If the code quality is approved, then I fix README and remove WIP mark.

maximkrouk avatar Jul 28 '20 04:07 maximkrouk

Hey! How are things going with this? I'm looking to start a project using Vapor 4 and I'd love to use this! Any update would be great 😎

jamesolrog avatar Dec 28 '20 18:12 jamesolrog

As far as I remember it is ready for use, but I wasn't sure if the architecture fits vapor 4. Now I don't have time to maintain or improve the project, but my fork still should probably work 🌚

maximkrouk avatar Dec 28 '20 18:12 maximkrouk

Haha okay thanks I'll give that a go!

I'm wanting to create a simple web app to communicate with a pre-existing Firebase DB and it would just save me a tonne of time so I'm keen to see if I can get it working 🤓

jamesolrog avatar Dec 28 '20 20:12 jamesolrog

@jamesolrog Did you get it to build?

garymansted avatar Jan 02 '21 11:01 garymansted

@garymansted I couldn't get @maximkrouk 's branch to work completely. I followed the updated instructions and, quickly looking at it, everything seems like it should work. However, when SPM resolves, I get a "product dependency 'Ferno' in package 'ferno' not found" error and I'm not certain of what is causing it.

My next step was to clone the repository and drag in the files locally (taking the package manager out of the equation) to see if I can get the code itself to work but haven't got round to it yet!

jamesolrog avatar Jan 02 '21 23:01 jamesolrog

Hi @jamesolrog thanx for your response. I tried the same thing as you and got the same error - hence my asking. I got it to work after using your wisdom and insight by 'taking the package manager out of the equation'. For anyone wanting to know the full process of how I got it to work this is what I did.

I cloned the repository and dragged the files in (making sure that they were in the right place in the file tree). Screen Shot 2021-01-04 at 10 51 23 am Then added the Ferno config to the apps configure.swift file

public func configure(_ app: Application) throws {

let fernoConfiguration = FernoConfiguration(
    basePath: "database-url",
    email: "service-account-email",
    privateKey: "private-key"
)

Tip: Be sure to include the https:// protocol in the basePath: "https://example1234.firebaseio.com"

Then I registered it: app.ferno.use(.default(fernoConfiguration))

My specific usage was just to post (update) some data to my Firebase:

struct BitcoinData: Content {
    var symbol: String
    var price: String
}
private func postResults(app: Application, symbol: String, price: String) {
      let request = Request(application: app, on: app.eventLoopGroup.next())
      let newPrice = BitcoinData(symbol: symbol, price: price)
      do {
          try app.ferno.update("bitcoinPrice", body: newPrice, on: request)
      }
      catch {
          print(error.localizedDescription)
      }
}

@maximkrouk Thanx for your work on this update! Hope this helps someone.

garymansted avatar Jan 04 '21 00:01 garymansted

@garymansted Cracking stuff Gary. I'm gunna follow your instructions this week so hopefully I'll be up and running too! Best of luck with your project 😎.

@maximkrouk just curious to whether there is a super easy fix for the error we have discussed?

Just seems like a very weird error considering the previous version's packages appear to work! I appreciate your time is really valuable so no worries if you can't take a look. 💪🏼

jamesolrog avatar Jan 04 '21 09:01 jamesolrog

@garymansted I couldn't get @maximkrouk 's branch to work completely. I followed the updated instructions and, quickly looking at it, everything seems like it should work. However, when SPM resolves, I get a "product dependency 'Ferno' in package 'ferno' not found" error and I'm not certain of what is causing it.

My next step was to clone the repository and drag in the files locally (taking the package manager out of the equation) to see if I can get the code itself to work but haven't got round to it yet!

Probably the name of the package is case-sensitive "Ferno", so you can edit it in target dependencies or specify a custom name in package dependencies with .package(name:url:from:) overload

maximkrouk avatar Jan 04 '21 09:01 maximkrouk

@maximkrouk ahhh sure. Thank you for getting back to me! 💙

I did try something like this but interestingly:

  • Trying to force the package 'name' to lowercase results in a "declared name 'ferno' does not match actual package name 'Ferno'".

and

  • Using the given package dependency and just changing the target product's package name from 'ferno' to 'Ferno' results in a "unknown package 'Ferno' in dependencies of target 'App'"

By playing around with this, I was able to find a combination that worked:

In the package dependencies:

.package(name: "Ferno", url: "https://github.com/maximkrouk/ferno.git", .branch("master"))

and in the package targets:

targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Leaf", package: "leaf"),
                .product(name: "Vapor", package: "vapor"),
                .product(name: "Ferno", package: "Ferno")
            ],
...

Hope this helps. @garymansted give the above a try and you should be able to remove those local files now! haha 😁

jamesolrog avatar Jan 04 '21 21:01 jamesolrog