Skip to content

Commit

Permalink
Merge pull request #4 from fdoxyz/aasa-support
Browse files Browse the repository at this point in the history
Direct AASA Support
  • Loading branch information
fdocr authored Aug 23, 2021
2 parents 9069819 + 045c482 commit 2b6dc54
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
Expand All @@ -14,7 +16,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.0
ruby-version: 3.0.2
- name: Install dependencies
run: bundle install
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.2
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ DEPENDENCIES
sinatra-reloader (~> 1.0)

RUBY VERSION
ruby 3.0.0p0
ruby 3.0.2p107

BUNDLED WITH
2.2.15
2.2.22
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The server is hosted at [`https://udl.visualcosita.com`](https://udl.visualcosit

## How it works, and why?

It's a dead simple pivot server that will redirect to whatever you pass in the `r` query param to the root path.
It's a dead simple pivot server that will allow for Universal Links to work with you app.

Modern mobile browsers provide developers with [Universal Links (iOS)](https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html) or [Android Intents](https://developer.chrome.com/docs/multidevice/android/intents/) to support deep linking users from a website directly into a mobile app. However, Operating Systems currently won't trigger these features when the user clicks a link within the same domain or when the user types the URL directly in the address bar.

Expand All @@ -28,6 +28,10 @@ Power users will likely need better reliability and scalability than a free serv
- `git remote add upstream [email protected]:fdoxyz/udl-server.git`
- `git pull upstream main`
- `git push origin main`
1. Configure `AASA_APP_ID` ENV variable to match your App Id
- Use the team ID or app ID prefix, followed by the bundle ID (joined by a dot `.`).
- This will allow your UDL Server to directly serve as a Universal Link target for your app and improve the experience
- Example: `R9SWHSQNV8.com.forem.app`

## Throttling, Safelist and Blocklist

Expand Down
38 changes: 33 additions & 5 deletions server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
end

require 'uri'
require 'json'
require 'redis-activesupport'
require 'rack/attack'

if ENV['REDIS_URL'].present?
Rack::Attack.cache.store = ActiveSupport::Cache.lookup_store :redis_store
Rack::Attack.cache.store = ActiveSupport::Cache.lookup_store :redis_store

limit = (ENV['UDL_THROTTLE_LIMIT'] || 3).to_i
period = (ENV['UDL_THROTTLE_PERIOD'] || 10).to_i
if ENV['UDL_THROTTLE_LIMIT'].present? && ENV['UDL_THROTTLE_PERIOD'].present?
limit = ENV['UDL_THROTTLE_LIMIT'].to_i
period = ENV['UDL_THROTTLE_PERIOD'].to_i
Rack::Attack.throttle('requests/ip', limit: limit, period: period) do |request|
request.ip
end
Expand Down Expand Up @@ -45,6 +46,33 @@
end
end

get '/.well-known/apple-app-site-association' do
aasa_app_id = ENV['AASA_APP_ID'].to_s
content_type :json
{
"applinks": {
"apps": [],
"details":[
{
"appID": aasa_app_id,
"paths": ["/*"]
}
]
},
"activitycontinuation": {
"apps": [aasa_app_id]
}
}.to_json
end

get '/*' do
erb :fallback
begin
target_url = URI(params['splat'].first)
raise 'Invalid redirect URL' if target_url.host != request.host
redirect target_url
rescue => error
@error = error
logger.info @error.inspect
erb :fallback
end
end

0 comments on commit 2b6dc54

Please sign in to comment.