Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide on how to integrate with non-example app #10

Open
ninokierulf opened this issue Jun 8, 2017 · 21 comments
Open

Guide on how to integrate with non-example app #10

ninokierulf opened this issue Jun 8, 2017 · 21 comments

Comments

@ninokierulf
Copy link

Hi,

I have a production app, and I would like to do some POC regarding client-side server.
As the sample makefile and scripts are hardcoded for the sample xcodeproj,
is there any way the integration to be simpler?

Thank you

@vadimeisenbergibm
Copy link
Member

Hi @ninokierulf

The idea of this is to provide an example project and set of example scripts that can be customized/ taken as a basis for developing projects that would use Kitura/iOS. We will publish a new layout soon, currently it is in https://github.com/rodedz/Kitura-HelloWorld-iOS. In the new layout we use git sub-modules for ClientSide, ServerSide and Builder scripts. So it will be possible to reuse/replace ClientSide and ServerSide parts independently.

I would love to hear your ideas about simplifying the project. BTW, I am at WWDC this week, if you or your colleagues are here, we can discuss your work. There are also Kitura sessions at AltConf.

Thanks,
Vadim

@nerdo
Copy link

nerdo commented Oct 8, 2017

Some guidance here would be helpful.

Conceptually, I understand how git submodules work but haven't used them much in practice. Beyond just the git knowledge, though, I'm not sure how to handle certain things.

For example, I started a new project based on this and added a few swift files to the Kitura-HelloWorld project. I needed to add a dependency (Kitura-WebSockets) so I added it to the package file. I wasn't sure how to make everything update properly, so I ran make openXcode to re-generate everything. The problem is, it re-created the Xcode project without the swift files I added. I can easily add them back, but as the project grows I can see this being a pain point.

Any guidance on how to work with scenarios like this, and just on swapping out the pieces in general, would be appreciated.

@vadimeisenbergibm
Copy link
Member

@nerdo Sorry, I was on vacation.

The idea is that you first work with your Server Side project, e.g. Kitura-HelloWorld as with any other Server Side project - updating its Package.swift and verifying that it works on Mac as a command line Mac program. You commit your changes to your Server Side project. Then you remove ServerSide directory from your iOS project and run make openXcode. It fill fetch the latest version of ServerSide submodule with your changes.

In short, just remove ServerSide directory in your iOS project whenever new commits are added to the ServerSide git repository, and rerun make openXcode.

I hope it helps.

@vadimeisenbergibm
Copy link
Member

@ninokierulf @nerdo I just published a blog post describing the technical issues involved in development of Kitura/iOS applications. Kitura/iOS Part 2: Software Engineering Principles of iPhone Web Servers

@svenyonson
Copy link

I just found Part 2 - Excellent, thank you. It answered many of my questions regarding the package/framework issues and the general layout of the workspace.

One question: How can I get a callback that the server is listening/ready? I am adding a UIWebView to the project so I can serve web content internally, but I can't load a url until Kitura is ready.

@vadimeisenbergibm
Copy link
Member

vadimeisenbergibm commented Feb 11, 2018

@svenyonson You are welcome.

One question: How can I get a callback that the server is listening/ready? I am adding a UIWebView to the project so I can serve web content internally, but I can't load a url until Kitura is ready.

Hmm, maybe I miss something, but I think the start of the server is synchronous - the server is started after Kitura.start() finishes. I guess you saw how it is started here https://github.com/IBM-Swift/Kitura-Mobile-Server/blob/87dd1bee02625bd8be6126c8b550af5d0563d7d5/KituraiOS/KituraTableViewController.swift#L70.

So I think it is up to your code to run Kitura.start() first, and then to issue requests to it.

@svenyonson
Copy link

svenyonson commented Feb 11, 2018 via email

@svenyonson
Copy link

I'm just finishing up on the Monkey See/Do clone/refactor of the build environment. Whew, not for the faint of heart - I'm a little anxious about what happens when XCode 10/11 comes out and how much of the scripts in Kitura-iOS-Build will have to be reworked. But it works now, and thanks for all the effort you put into the build management component.

I'm now trying to have Kitura serve real pages. I added Kitura Stencil and that is now fetching the package. But I'm confused about the resource folders. Should I be adding my template/resource files to ServerSide folders and then run make openXcode whenever I make changes? Or can I just add files to the client public/Views folders? Not sure if the ServerSide needs them? Also, why does the client need to copy the .build files from the client to the device? Isn't everything already part of the Kitura frameworks in ServerSide?

@svenyonson
Copy link

I've got it working now by just adding resource files to public and Views and it seems to work fine. I don't imagine adding those folders to ServerSide, so at least for now not an issue.

@vadimeisenbergibm
Copy link
Member

@svenyonson

I'm a little anxious about what happens when XCode 10/11 comes out and how much of the scripts in Kitura-iOS-Build will have to be reworked

Yep, until Swift Package Manager is integrated with Xcode, the integration has to be performed by Ruby scripts.

Should I be adding my resource files to ServerSide folders and then run make openXcode whenever I make changes?

The goal is to run the same ServerSide inside an iPhone App and outside it, on a Mac/Linux/Cloud. If you do not need to use ServerSide as a remote backend for your iPhone App, at least you can use it for testing. I think it could be convenient to be able to test and run ServerSide separately. From that goal follows that the resources should be in the ServerSide, since you want to serve them when running outside your iPhone app as well.

BTW, can you share what you use Kitura/iOS for? I imagined the use cases here - https://developer.ibm.com/swift/2017/03/13/kitura-ios/, and I am just curious to know what the people would really use it for.

why does the client need to copy the .build files from the client to the device?

This one is tricky :) It is to serve the Kitura welcome page from the sources (Kitura reads the welcome page from its source - https://github.com/IBM-Swift/Kitura/tree/master/Sources/Kitura/resources. While this is not really needed, the goal was, again, to make Kitura behave identically on the server and inside the iPhone app. This copying can be skipped if you do not have a really strong desire to display the Kitura welcome page.

@svenyonson
Copy link

svenyonson commented Feb 12, 2018 via email

@vadimeisenbergibm
Copy link
Member

Interesting, I always thought that the native UI is always better than HTML5. So in your case you want to get more stability, to be protected from the Apple's changing APIs, and, I guess, you are ready to sacrifice the sleek features of iPhone native UI.

I am glad Kitura helps you in this case.

This lets me rapidly iterate web page implementations (using Stencil) with a desktop browser - and without having to rebuild/cableload my iOS device for every little CSS change.

Yep, this is the supposed killer argument - you can run Kitura on a desktop and inside the iPhone app.

Regarding closing the port in production - I did not think about it, I do not know how to do it.

@svenyonson
Copy link

In this case, the app is merely a container for content - no fancy native UI features needed. Plus, you can do some pretty slick stuff with CSS3 these days. And the bonus is that now my app is cross platform - hoping Kitura will make its way to Android someday.

@svenyonson
Copy link

So, I guess I don't really need a separate macOS project - I can select and build the Server project, but it doesn't run. (eg. Kitura-HelloWorld project) Is there a setting somewhere to enable this?

@svenyonson
Copy link

Ah, I found it under Edit Schemes.

@svenyonson
Copy link

Hmmm, I started over with a fresh pull of Kitura-HelloWorld-iOS, and I'm trying to build/run Kitura-HelloWorld on the Mac - Isn't this supposed to work? Or is this target just a framework for the iOS app? There is no executable to select when I try to Edit the Scheme.

@vadimeisenbergibm
Copy link
Member

@svenyonson As far as I remember, the Xcode workspace will run on iOS only. To run it on Mac from Xcode, you can just regenerate the Xcode project (swift package generate-xcodeproj) in the ServerSide directory, open and run that project on Mac. You can use --output flag to give it another name, so it will not interfere with the Xcode project used in the Xcode workspace used for the Kitura/iOS app.

@svenyonson
Copy link

@vadimeisenbergibm - Thanks. I'm deep in the weeds trying to have a bit of sharable code between the iOS app and a macOS app. I tried creating a new framework from scratch but quickly got lost with dependent frameworks (eg. Kitura). SO - back to the original workspace, derived from your EndToEnd, I just added a new target to SharedServerClient (macOS), added the same frameworks to be linked with, and I am astonished to see that it built successfully. Shouldn't I be able to add a new project to the workspace that links with my new SharedServerClient and have a macOS Kitura server? I am going to proceed with caution but wanted to know if this is not ultimately possible and a waste of time. Thoughts?

@svenyonson
Copy link

All is well now. I gave up on having the shared code in frameworks. Easier to have Groups/Folders with paths set to folders in a sibling repository. The shared code is largely routes and then the public/Views for content. (On the macOS project I had to symlink the public/Views folders as I couldn't find a way to tell Kitura where to look for those folders). But, happily sharing content and routes between iOS and macOS Kitura applications now.

@vadimeisenbergibm
Copy link
Member

@svenyonson You can change the templates directory of Kitura, per Router, by setting viewsPath property, see https://github.com/IBM-Swift/Kitura/blob/4fbe57dee2a0fda61dd3ef03d3f845059acdae2a/Sources/Kitura/Router.swift#L74.

You can change the static files directory of the StaticFileServer middleware instances, by passing them path parameter, see an example at https://github.com/IBM-Swift/Kitura-Sample/blob/master/Sources/KituraSampleRouter/RouterCreator.swift#L90.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants