-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on client setup and server setup for SublimationNgrok
- Loading branch information
Showing
6 changed files
with
91 additions
and
26 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
Sources/SublimationNgrok/Documentation.docc/Documentation.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# ``SublimationNgrok`` | ||
|
||
Share your local development server easily with your Apple devices via Ngrok. | ||
|
||
![SublimationNgrok Diagram](SublimationNgrok.svg) | ||
|
||
## Overview | ||
|
||
Ngrok is a fantastic service for setting up local development server for outside access. Let's say you need to share your local development server because you're testing on an actual device which can't access your machine via your local network. You can run `ngrok` to setup an https address which tunnels to your local development server: | ||
|
||
```bash | ||
> vapor run serve -p 1337 | ||
> ngrok http 1337 | ||
``` | ||
Now you'll get a message saying your vapor app is served through ngrok: | ||
|
||
``` | ||
Forwarding https://c633-2600-1702-4050-7d30-cc59-3ffb-effa-6719.ngrok.io -> http://localhost:1337 | ||
``` | ||
|
||
With Sublimation you save the address (such as `https://c633-2600-1702-4050-7d30-cc59-3ffb-effa-6719.ngrok.io`) to a key-value storage and pull that address from your Apple device during development. | ||
|
||
### Cloud Setup | ||
|
||
If you haven't already setup an account with ngrok and install the command-line tool via homebrew. Next let's setup a key-value storage with kvdb.io which is currently supported. _If you have another service, please create an issue in the repo. Your feedback is helpful._ | ||
|
||
Sign up at kvdb.io and get a bucket name you'll use. You'll be using that for your setup. Essentially there are three components you'll need: | ||
|
||
* **ngrok executable path** | ||
- if you installed via homebrew it's `/opt/homebrew/bin/ngrok` but you can find out using: `which ngrok` after installation | ||
* your kvdb.io **bucket name** | ||
* your kvdb.io **key** | ||
- you just need to pick something unique for your server and client to use | ||
|
||
Save these somewhere in your shared configuration for both your server and client to access, such as an `enum`: | ||
|
||
```swift | ||
public enum SublimationConfiguration { | ||
public static let bucketName = "fdjf9012k20cv" | ||
public static let key = "my-" | ||
} | ||
``` | ||
|
||
### Server Setup | ||
|
||
When creating your `Sublimation` object you'll want to use the provided convience initializers ``SublimationTunnel/TunnelSublimatory/init(ngrokPath:bucketName:key:application:isConnectionRefused:ngrokClient:)`` to make it easier for **ngrok** integration with the ``SublimationTunnel/TunnelSublimatory``: | ||
|
||
```swift | ||
let tunnelSublimatory = TunnelSublimatory( | ||
ngrokPath: "/opt/homebrew/bin/ngrok", // path to ngrok executable | ||
bucketName: SublimationConfiguration.bucketName, // "fdjf9012k20cv" | ||
key: SublimationConfiguration.key, // "dev-server" | ||
application: { myVaporApplication }, // pass your Vapor.Application here | ||
isConnectionRefused: {$.isConnectionRefused}, // supplied by `SublimationVapor` | ||
transport: AsyncHTTPClientTransport() // ClientTransport for Vapor | ||
) | ||
|
||
let sublimation = Sublimation(sublimatory: tunnelSublimatory) | ||
``` | ||
|
||
### Client Setup | ||
|
||
For the client, you'll need to import the ``SublimationKVdb`` module and retrieve the url via: | ||
|
||
```swift | ||
let hostURL = try await KVdb.url( | ||
withKey: SublimationConfiguration.key, | ||
atBucket: SublimationConfiguration.bucketName | ||
) | ||
``` | ||
|
||
## Topics | ||
|
||
### Creating a Sublimatory | ||
|
||
- ``SublimationTunnel/TunnelSublimatory`` |
1 change: 1 addition & 0 deletions
1
Sources/SublimationNgrok/Documentation.docc/Resources/SublimationNgrok.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
Sources/SublimationNgrok/Documentation.docc/Resources/SublimationNgrok~dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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