{"id":13493067,"url":"https://github.com/fnando/sinatra-subdomain","last_synced_at":"2025-04-09T13:08:43.377Z","repository":{"id":901327,"uuid":"657339","full_name":"fnando/sinatra-subdomain","owner":"fnando","description":"Separate routes for subdomains in Sinatra apps","archived":false,"fork":false,"pushed_at":"2020-09-24T21:58:11.000Z","size":37,"stargazers_count":98,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-14T09:58:23.440Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["fnando"],"custom":["https://www.paypal.me/nandovieira/🍕"]}},"created_at":"2010-05-09T06:27:38.000Z","updated_at":"2023-11-06T12:03:06.000Z","dependencies_parsed_at":"2022-07-05T20:41:55.435Z","dependency_job_id":null,"html_url":"https://github.com/fnando/sinatra-subdomain","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsinatra-subdomain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsinatra-subdomain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsinatra-subdomain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsinatra-subdomain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/sinatra-subdomain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045233,"owners_count":21038553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:11.904Z","updated_at":"2025-04-09T13:08:43.353Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":["https://github.com/sponsors/fnando","https://www.paypal.me/nandovieira/🍕"],"categories":["Routers"],"sub_categories":[],"readme":"# Sinatra Subdomain\n\n[![Travis-CI](https://travis-ci.org/fnando/sinatra-subdomain.svg)](https://travis-ci.org/fnando/sinatra-subdomain)\n[![Code Climate](https://codeclimate.com/github/fnando/sinatra-subdomain/badges/gpa.svg)](https://codeclimate.com/github/fnando/sinatra-subdomain)\n[![Gem](https://img.shields.io/gem/v/sinatra-subdomain.svg)](https://rubygems.org/gems/sinatra-subdomain)\n[![Gem](https://img.shields.io/gem/dt/sinatra-subdomain.svg)](https://rubygems.org/gems/sinatra-subdomain)\n\n## Installation\n\n```\ngem install sinatra-subdomain\n```\n\n## Usage\n\n```ruby\nrequire \"sinatra\"\nrequire \"sinatra/subdomain\"\n\n# Specify which subdomain you want\nsubdomain :foo do\n  get \"/\" do\n    \"render page for FOO\"\n  end\nend\n\n# If any subdomain is set\nsubdomain do\n  get \"/\" do\n    \"render page for #{subdomain} subdomain\"\n  end\nend\n```\n\nIf you're not building a classic app, make sure to register Sinatra::Subdomain\nyourself:\n\n```ruby\nrequire \"sinatra\"\nrequire \"sinatra/subdomain\"\n\n# Specify which subdomain you want\nclass MyApp \u003c Sinatra::Base\n  register Sinatra::Subdomain\n\n  subdomain :foo do\n    get \"/\" do\n      \"render page for FOO\"\n    end\n  end\n\n  # If any subdomain is set\n  subdomain do\n    get \"/\" do\n      \"render page for #{subdomain} subdomain\"\n    end\n  end\nend\n```\n\nYou can also pass an array, regular expressions to match subdomains, or a proc:\n\n```ruby\nclass MyApp \u003c Sinatra::Base\n  register Sinatra::Subdomain\n\n  subdomain [:foo, :bar, :zaz] do\n    get \"/\" do\n      \"render page for #{subdomain}\"\n    end\n  end\n\n  # Matches www, www1, www2, etc.\n  subdomain /\\Awww\\d*\\z/ do\n    get \"/\" do\n      \"render page for #{subdomain} subdomain\"\n    end\n  end\n\n  app_matcher = lambda do |subdomain|\n    App.where(subdomain: actual_subdomain).exist?\n  end\n\n  subdomain(app_matcher) do\n    get \"/\" do\n      \"render page for #{subdomain} app\"\n    end\n  end\nend\n```\n\nBy default, sinatra-subdomain will consider 1 TLD as in \u003ctt\u003eexample.com\u003c/tt\u003e.\nYou can specify your TLD size for domains like \u003ctt\u003eexample.com.br\u003c/tt\u003e or\n\u003ctt\u003eexample.co.uk\u003c/tt\u003e.\n\n```ruby\nrequire \"sinatra\"\nrequire \"sinatra/subdomain\"\n\nset :tld_size, 2\n```\n\n# License\n\n(The MIT License)\n\nCopyright © 2010 - Nando Vieira (http://nandovieira.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the ‘Software’), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fsinatra-subdomain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fsinatra-subdomain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fsinatra-subdomain/lists"}