1

I am building an application using the Scalatra framework, and need to expose one external facing endpoint which I would like to mount on a different port. I am having trouble seeing how to configure my application to do so

class ScalatraBootstrap extends LifeCycle {

    override def init(context: ServletContext): Unit = {
        // I would like to mount these on two different ports
        context mount (new InternalApi, "/api", "api") 
        context mount (new ExternalApi, "/") 
    }

    override def destroy(context: ServletContext): Unit = {

    }
}

Is there a way to do this, or do I need to run multiple Jetty servers inside my application? Any help in pointing me in the right direction would be greatly appreciated!

user1875195
  • 968
  • 4
  • 8
  • 22
  • Look for `ServerConnector` and/or `Connector` configuration in your app. the init() and destroy() you are showing is for a specific webapp, you need to go more general, to the server itself. – Joakim Erdfelt Aug 31 '15 at 21:12
  • Alright I'll do some reading on that. Does this mean that I will need multiple "ScalatraBootraps" to configure multiple webapps? – user1875195 Aug 31 '15 at 21:18
  • Perhaps, all I can comment on is Jetty itself. It supports multiple connectors (the concept that listens for incoming connections) on multiple ports (and network interfaces), as well as multiple webapps. – Joakim Erdfelt Aug 31 '15 at 21:19
  • 1
    The ScalatraBootstrap is not aware of "ports", it usually mounts servlets to specific URLs. You need to configure the HTTP server (e.g. Jetty). How you do this depends whether you run the Scalatra application as a .war in an external servlet container or in an embedded servlet container. In the latter case the Jetty is configured in your application, in the first case it is configured externally. You can take a look at https://github.com/scalatra/scalatra-in-action (chapter09, chapter09-standalone). – Stefan Ollinger Sep 01 '15 at 09:44

0 Answers0