trailsjs / trails

:evergreen_tree: Modern Web Application Framework for Node.js.
http://trailsjs.io
Other
1.67k stars 70 forks source link

Trails fails to boot if path is array #298

Closed gliwka closed 2 years ago

gliwka commented 6 years ago

Issue Description

I've defined a custom www path in config/main.js according to the trailpack-hapi documentation:

/**
 * Trailpack Configuration
 * (app.config.main)
 *
 * @see http://trailsjs.io/doc/config/main
 */

'use strict'

const path = require('path')

module.exports = {

  /**
   * Order does *not* matter. Each module is loaded according to its own
   * requirements.
   */
  packs: [
    require('trailpack-repl'),
    require('trailpack-router'),
    require('trailpack-hapi'),
    require('trailpack-waterline'),
    require('trailpack-footprints')
  ],

  /**
   * Define application paths here. "root" is the only required path.
   */
  paths: {
    root: path.resolve(__dirname, '..'),
    temp: path.resolve(__dirname, '..', '.tmp'),
    www: [
      {
        path: path.resolve(__dirname, '..', 'static'),
        humanUrl: '/admin'
      }
    ]
  }
}

Trails now fails to start because the current implementation of trails core treats each path entry as path and doesn't check for arrays any more. Compare current lib/core.js#L103 with an older implementation.

Is this feature deprecated? In this case the documentation should be updated accordingly and trailpack-hapi updated because it still contains the implementation to handle path arrays.

The error during bootup for completeness:

➜  demo git:(master) ✗ npm start

> demo@0.0.0 start /home/mg/projects/meta/demo
> node server.js

(node:15935) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
error: 
 TypeError: path must be a string or Buffer
    at Object.fs.stat (fs.js:893:11)
    at Promise (/home/mg/projects/meta/demo/node_modules/trails/lib/core.js:103:12)
    at Promise.all._.map (/home/mg/projects/meta/demo/node_modules/trails/lib/core.js:102:14)
    at /home/mg/projects/meta/demo/node_modules/trails/node_modules/lodash/lodash.js:3579:27
    at /home/mg/projects/meta/demo/node_modules/trails/node_modules/lodash/lodash.js:4970:15
    at baseForOwn (/home/mg/projects/meta/demo/node_modules/trails/node_modules/lodash/lodash.js:3020:24)
    at /home/mg/projects/meta/demo/node_modules/trails/node_modules/lodash/lodash.js:4939:18
    at baseMap (/home/mg/projects/meta/demo/node_modules/trails/node_modules/lodash/lodash.js:3578:7)
    at Function.map (/home/mg/projects/meta/demo/node_modules/trails/node_modules/lodash/lodash.js:9556:14)
    at Object.createDefaultPaths (/home/mg/projects/meta/demo/node_modules/trails/lib/core.js:101:26)
    at TrailsApp.createPaths (/home/mg/projects/meta/demo/node_modules/trails/index.js:306:21)
    at app.after.then (/home/mg/projects/meta/demo/node_modules/trails/lib/trailpack.js:16:23)
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
error: The application did not boot successfully.
error: Try increasing the loglevel to "debug" to learn more
info: Shutting down...
(node:15935) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'removeAllListeners' of undefined
(node:15935) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Environment

scott-wyatt commented 6 years ago

this is interesting, I'm not sure If this was intended use, but I see the value to something like this. Are you using hapi, express, etc...?