trailsjs / trailpack-hapi

:package: Hapi.js Trailpack
MIT License
19 stars 9 forks source link

Serving Static Assets #103

Closed smythey21 closed 8 years ago

smythey21 commented 8 years ago

I'm trying to get my server to serve static assets in a folder called frontend/dist, but nothing seems to be working. I tried setting the www path in config/main.js but it my server keeps returning {"statusCode":404,"error":"Not Found"}.

  // config/main.js

  paths: {
    root: path.resolve(__dirname, '..'),
    temp: path.resolve(__dirname, '..', '.tmp'),
    www: path.resolve(__dirname, '..', 'frontend/dist')
  }

I also tried using the directory handler found in inert:

  // config/web.js

  plugins: [{
    register: require('inert'),
    options: { }
  }]
// config/routes.js

module.exports = [
  {
    method: 'GET',
    path: '/{param*}',
    handler: {
        directory: {
            path: 'frontend/dist'
        }
    }
  }
]

But this returns a validation error:

error:
 ValidationError: child "handler" fails because ["handler" must be a Function, "handler" must be a string]

Any thoughts on why setting the www does nothing or how I can get the directory handler working?

Update

I've raised the validation error as an issue in trailpack-router

weyj4 commented 8 years ago

@smythey21 what you're doing should work. It's related to this PR: https://github.com/trailsjs/trailpack-hapi/pull/86 . It hasn't been merged because it needs to be updated to work with Windows. I'll get it working ASAP.

smythey21 commented 8 years ago

👍 Works after referencing latest in master. Thanks @weyj4