title: HapiJS - Static Files
body: <p>I am trying to create a plugin for serving my static files in HapiJS. My file structure is the following</p>
  
  <pre><code>|_ plugins
  |  |_ assets
  |    |_ assets.js
  |    |_ package.json 
  |  |_ views
  |_ public
  |  |_ css
  |app.js
  | config.json
  | package.json
  </code></pre>
  
  <p>Within my plugins/assets/assets.js file I have the following code:</p>
  
  <pre><code>const Inert = require('inert');
  
  exports.register = function(server, options, next) {
  
      server.register('inert');
  
      server.route({
          method: 'GET',
          path: '/{public}',
          handler: {
              directory: {path: '../../public'}
          }
      });
  
      next();
  };
  
  exports.register.attributes = {
      pkg: require('./package');
  }
  </code></pre>
  
  <p>Within my config.json file (glue manifest):</p>
  
  <pre><code>{
    "server": {
      "app": {
        "slogan": "We push the web forward"
      }
    },
    "connections": [
      {
        "port": 3000,
        "labels": ["web-ui"]
      }
    ],
    "registrations": [
      {"plugin": "vision"},
      {"plugin": "inert"},
      {"plugin": "glue"},
      {"plugin": "./plugins/assets"}
    ]
  }
  </code></pre>
  
  <p>And finally, in my app.js:</p>
  
  <pre><code>var Hapi = require('hapi');
  var Glue = require('glue');
  
  var manifest = require('./config.json');
  
  const options = {
      relativeTo: __dirname
  };
  
  Glue.compose(manifest, options, function (err, server) {
      server.start(function(err) {
          console.log('Server running');
      });
  });
  </code></pre>
  
  <p>My question is this the correct way to serve static files using a plugins approach with glue? All the examples I have seen do not use a plugin approach and instead use the server.register() within the app.js file to serve the static files from the public directory.</p>