Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:49:59+00:00 2026-06-09T18:49:59+00:00

I developed a Rack application based on Sinatra::Base . Now I would like to

  • 0

I developed a Rack application based on Sinatra::Base. Now I would like to use many instances of it, each with a slightly different configuration, in a single Rack application.

My rackup should look like

use Rack::Lint

map '/mel' do
    run Site.new('/home/mel/site').app
end

map '/pub' do
    run Site.new('/pub').app
end

The Site class collects various parameters (in this example only the root dir) and does some preparatory work. The #app method should return a Server object that holds a reference to the served Site instance.

This is an example of the Site and Server code:

class Site
    def initialize(root_dir)
        @root_dir = root_dir
        # ... set up things ...
    end

    def app
        # This is where a new Server Rack application should be created
        return Server.new { |server| server.set :site, self }
    end
end

class Server < Sinatra::Base
    before do
        @content = settings.site.all_files
    end

    get /(.*)/ do |url_path|
        # do things...
    end
end

The problem with this code is that the #app method does not return a valid Rack application.

What should I do in #app to return a new, configured Server Rack application?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:50:01+00:00Added an answer on June 9, 2026 at 6:50 pm

    This is a way to make it work suggested by “carloslopes” on #sinatra.

    The Site#app method becomes

    class Site
        def app
            # This is where a new Server object should be created
            return Server.new(self)
        end
    end
    

    and the Server objects get their parameters via instance variables:

    class Server < Sinatra::Base
        def initialize(site)
            super()
            @site = site
        end
    
        before do
            @content = @site.all_files
        end
    
        get /(.*)/ do |url_path|
            # do things...
        end
    end
    

    Edit: made community wiki so that other can make the solution even better and share the credit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used Rack::Bug more than one year ago, now I'd like to use it
I developed an Android application and published it in the Market. Now I want
I developed a sample clock (Analog) application to display the time. Now my application
I developed a web-based training matrix that shows the training record for each employee
We developed a Seam 2 based Java EE 5 application and it runs on
I developed a Tomcat application using Tomcat 6 for testing. I have now deployed
I developed two .jar for my application (LOG.jar and STRING.jar). I use these jar,
I developed a winform application using C# in visual studio 2008. Now i want
While I develop, I would like to see sinatra app exceptions when running tests,
I developed my site and it works like a charm on my local machine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.