Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ You can pass the following options via cli arguments, every options has the corr
| Watch process.cwd() directory for changes, recursively; when that happens, the process will auto reload. | `-w` | `--watch` | `FASTIFY_WATCH` |
| Use custom options | `-o` | `--options` | `FASTIFY_OPTIONS` |
| Set the prefix | `-r` | `--prefix` | `FASTIFY_PREFIX` |
| Set the plugin timeout | `-T` | `--plugin-timeout` | |
| Defines the maximum payload, in bytes,<br>the server is allowed to accept | | `--body-limit` | `FASTIFY_BODY_LIMIT` |

By default `fastify-cli` runs [`dotenv`](https://www.npmjs.com/package/dotenv), so it will load all the env variables stored in `.env` in your current working directory.

The default value for `--plugin-timeout` is 10 seconds.

#### fastify version discovery

Expand Down
3 changes: 3 additions & 0 deletions help/start.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ Usage: fastify start [opts] <file>
[env: FASTIFY_BODY_LIMIT]
Defines the maximum payload, in bytes, the server is allowed to accept

-T, --plugin-timeout
The maximum amount of time that a plugin can take to load (default to 10 seconds).

-h, --help
Show this help message
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"chokidar": "^2.0.4",
"commist": "^1.0.0",
"dotenv": "^6.0.0",
"fastify": "^1.9.0",
"fastify": "^1.11.0",
"fastify-plugin": "^1.2.0",
"generify": "^3.0.0",
"help-me": "^1.1.0",
Expand Down
8 changes: 6 additions & 2 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ function minimistArgs (args) {
watch: 'w',
prefix: 'r',
'log-level': 'l',
'pretty-logs': 'P'
'pretty-logs': 'P',
'plugin-timeout': 'T'
}
})
}
Expand Down Expand Up @@ -123,7 +124,10 @@ function runFastify (args, cb) {
const options = {
logger: {
level: opts['log-level']
}
},

// everything should load in 10 seconds
pluginTimeout: opts['plugin-timeout'] || 10 * 1000
}

if (opts['body-limit']) {
Expand Down
10 changes: 10 additions & 0 deletions test/data/timeout-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

// This is a counter example. WILL NOT WORK!
// the next function is not called
module.exports = function (fastify, opts, next) {
fastify.get('/', function (req, reply) {
reply.send({ wont: 'work' })
})
// next() not called on purpose
}
17 changes: 16 additions & 1 deletion test/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('should start fastify with custom options', t => {
// or because the server is booted without the custom options
try {
const argv = [ '-p', getPort(), '-o', 'true', './examples/plugin-with-options.js' ]
start.start(argv)
start.start(argv).close()
t.fail('Custom options')
} catch (e) {
t.pass('Custom options')
Expand Down Expand Up @@ -126,6 +126,21 @@ test('should only accept plugin functions with 3 arguments', t => {
start.start(argv)
})

test('should error with a good timeout value', t => {
t.plan(1)

const start = proxyquire('../start', {
'assert': {
ifError (err) {
t.equal(err.message, `ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time: ${__dirname}/data/timeout-plugin.js`)
}
}
})

const argv = [ '-p', '3040', '-T', '100', './test/data/timeout-plugin.js' ]
start.start(argv)
})

test('should throw on file not found', t => {
t.plan(1)

Expand Down