lucky_subdomain
LuckySubdomain
Subdomain support for Lucky apps.
Installation
-
Add the dependency to your
shard.yml
:dependencies: lucky_subdomain: github: matthewmcgarvey/lucky_subdomain
-
Run
shards install
Usage
require "lucky_subdomain"
Include the module in any action you want subdomain support for.
class BrowserAction < Lucky::Action
include LuckySubdomain
end
Define your subdomain restriction.
class BrowserAction < Lucky::Action
include LuckySubdomain
register_subdomain # subdomain required but any will do
register_subdomain "admin" # subdomain must equal "admin" (admin.example.com)
register_subdomain /(prod|production)/ # subdomain must match regex
register_subdomain ["tenant1", "tenant2", /tenant\d/] # subdomain must match one of the items
end
After defining the subdomain restriction, you can access the subdomain value from your route block
get "/users" do
tenant = Tenant.new.name(subdomain).first
users = UserQuery.new.tenant(tenant)
html IndexPage, users: users
end
If you would like to skip the subdomain requirement, you can add this to the top of your action class
skip _match_subdomain
Local Development
If you try to register a subdomain and access it locally using subdomain.127.0.0.1:3000
you will receive an error. To get around this you can do one of two things:
- Always use
subdomain.localhost:3000
and settld_length
to 0 in development (make sure it is not set to 0 when deployed) - Update your
/etc/hosts
file with a development url
Contributing
- Fork it (https://github.com/matthewmcgarvey/lucky_subdomain/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- matthewmcgarvey - creator and maintainer
Repository
lucky_subdomain
Owner
Statistic
- 1
- 0
- 0
- 0
- 3
- over 3 years ago
- April 3, 2021
License
MIT License
Links
Synced at
Sat, 23 Nov 2024 10:01:52 GMT
Languages