lucky_subdomain
Version, currently master branch1 version
- master branchlatestJul 9, 2021
github.com/matthewmcgarvey/lucky_subdomain
No description declared in shard.yml.
Installation
# Add this to your shard.yml
dependencies:
lucky_subdomain:
github: matthewmcgarvey/lucky_subdomain
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
1.0.0- License
- MIT
- Author
- matthewmcgarvey
Dependencies
Runtime Dependencies
Development Dependencies
- ameba~> 0.14github: crystal-ameba/amebadev
README
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:3000and settld_lengthto 0 in development (make sure it is not set to 0 when deployed) - Update your
/etc/hostsfile 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
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Jul 9, 2021
- Crystal
1.0.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/matthewmcgarvey/lucky_subdomain
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1