Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Assets - Not taking objects into account #116

Open
crash83k opened this issue Sep 16, 2016 · 2 comments
Open

Multiple Assets - Not taking objects into account #116

crash83k opened this issue Sep 16, 2016 · 2 comments

Comments

@crash83k
Copy link

I'm attempting to use multiple static directories. You can use the example shown in the documentation, it will fail.

It attempts to make the DIR but doesn't check if it's an object, instead expects a string.

This will work.
www: path.resolve(__dirname, '..', 'static')

This will not.

www: [
      {
        path: path.resolve(__dirname, '..', 'static'),
        humanUrl: '/admin'
      },
      {
        path: path.resolve(__dirname, '..', 'uploads', 'pictures', 'cats'),
        humanUrl: '/cats'
      }
    ]

This will eventually get to trailpack-core (line 46)

// create paths if they don't exist
    return Promise.all(Object.keys(paths).map(pathName => {
      const dir = paths[pathName]

      try {
        const stats = fs.statSync(dir)

        if (!stats.isDirectory()) {
          this.log.error('The path "', pathName, '" is not a directory.')
          this.log.error('config.main.paths should only contain paths to directories')
          return Promise.reject()
        }
      }
      catch (e) {
        fs.mkdirSync(dir)
      }
    }))
  }

And dir will be the object, not the string. Thus, an error will be thrown killing the server.

@jaumard
Copy link
Contributor

jaumard commented Sep 17, 2016

@crash83k can you link to the documentation where you read this ? Because yes it will not work main.paths are simple key/value.

If you want multiple static directories you have to add them under config/routes like this :

[
{
    method: 'GET',
    path: '/static1',
    handler: {
      directory: {
        path: 'node_modules'
      }
    }
  },{
    method: 'GET',
    path: '/static2',
    handler: {
      directory: {
        path: 'myDir'
      }
    }
  },
]

@jaumard
Copy link
Contributor

jaumard commented Sep 17, 2016

@crash83k I just miss an update sorry :) so yes this will work but new version of trailpack-core witch this functionality is not on npm yet for for now, so it's not working but you can use what I say on previous comment.
cc @konstantinzolotarev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants