Bastian
Bastian

Reputation: 4738

Dropwizard 0.8.0: serve static assets from /

I want my server to serve the static html files from /. Furthermore, css and js files should be served from /css respectively, /js. All json data should be accessible at /api.

However, I get a 404 for http://localhost:8080/ or any other path.

I use the following setting in the configuration file:

server:
  type: simple
  rootPath: /api/*

The application.initialize method looks like this:

@Override
public void initialize(io.dropwizard.setup.Bootstrap<MyConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css"));
    bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js"));
    bootstrap.addBundle(new AssetsBundle("/assets/pages", "/", "index.html", "html"));
}

Upvotes: 4

Views: 2257

Answers (1)

Edd
Edd

Reputation: 3822

I've just had to work through a similar problem (The documentation isn't the clearest, although with hindsight I guess most of the information is there somewhere), which I've resolved by setting both the applicationContextPath and the rootPath in my application config:

server:
  type: simple
  rootPath: /api/*
  applicationContextPath: /

The default value for applicationContextPath is "/application" in a simple server, so your complete root-path would have been "/application/api/*". If you don't need to use the simple server, you could alternatively use the default server, which has the applicationContextPath set to "/" by default:

server:
  rootPath: /api/*

Upvotes: 6

Related Questions