fastify-cli
Advanced tools
Comparing version 0.21.0 to 0.22.0
'use strict' | ||
const { test } = require('tap') | ||
const Fastify = require('fastify') | ||
const App = require('../../app') | ||
const { build } = require('../helper') | ||
test('example is loaded', (t) => { | ||
t.plan(2) | ||
const fastify = Fastify() | ||
fastify.register(App) | ||
const app = build(t) | ||
fastify.inject({ | ||
app.inject({ | ||
url: '/example' | ||
@@ -23,6 +21,5 @@ }, (err, res) => { | ||
// test('example is loaded', async (t) => { | ||
// const fastify = Fastify() | ||
// fastify.register(App) | ||
// const app = build(t) | ||
// | ||
// const res = await fastify.inject({ | ||
// const res = await app.inject({ | ||
// url: '/example' | ||
@@ -29,0 +26,0 @@ // }) |
'use strict' | ||
const { test } = require('tap') | ||
const Fastify = require('fastify') | ||
const App = require('../../app') | ||
const { build } = require('../helper') | ||
test('default root route', (t) => { | ||
t.plan(2) | ||
const fastify = Fastify() | ||
fastify.register(App) | ||
const app = build(t) | ||
fastify.inject({ | ||
app.inject({ | ||
url: '/' | ||
@@ -23,6 +21,5 @@ }, (err, res) => { | ||
// test('default root route', async (t) => { | ||
// const fastify = Fastify() | ||
// fastify.register(App) | ||
// const app = build(t) | ||
// | ||
// const res = await fastify.inject({ | ||
// const res = await app.inject({ | ||
// url: '/' | ||
@@ -29,0 +26,0 @@ // }) |
{ | ||
"name": "fastify-cli", | ||
"version": "0.21.0", | ||
"version": "0.22.0", | ||
"description": "Run a fastify route with one command!", | ||
@@ -54,2 +54,3 @@ "main": "cli.js", | ||
"is-docker": "^1.1.0", | ||
"make-promises-safe": "^1.1.0", | ||
"minimist": "^1.2.0", | ||
@@ -69,3 +70,3 @@ "pino-colada": "^1.4.4", | ||
"sinon": "^6.1.5", | ||
"standard": "^11.0.1", | ||
"standard": "^12.0.0", | ||
"tap": "^12.0.0", | ||
@@ -72,0 +73,0 @@ "walker": "^1.0.7" |
@@ -113,3 +113,3 @@ # fastify-cli | ||
#### fastify version discovery | ||
#### Fastify version discovery | ||
@@ -120,2 +120,39 @@ If Fastify is installed as a project dependency (with `npm install --save fastify`), | ||
#### Migrating out of fastify-cli start | ||
If you would like to turn your application into a standalone executable, | ||
just add the following `server.js`: | ||
```js | ||
'use strict' | ||
// Read the .env file. | ||
require('dotenv').config() | ||
// Require the framework | ||
const Fastify = require('fastify') | ||
// Instantiate fastify with some config | ||
const app = Fastify({ | ||
logger: true, | ||
pluginTimeout: 10000 | ||
}) | ||
// Register your application as a normal plugin. | ||
fastify.register(require('./app.js')) | ||
// Start listening. | ||
fastify.listen(process.env.PORT || 3000, (err) => { | ||
if (err) { | ||
fastify.log.error(err) | ||
process.exit(1) | ||
} | ||
}) | ||
``` | ||
#### Unhandled rejections | ||
fastify-cli uses [make-promises-safe](https://github.com/mcollina/make-promises-safe) to avoid memory leaks | ||
in case of a `'unhandledRejection'`. | ||
### generate | ||
@@ -122,0 +159,0 @@ |
@@ -49,2 +49,5 @@ #! /usr/bin/env node | ||
// we start crashing on unhandledRejection | ||
require('make-promises-safe') | ||
loadModules(opts) | ||
@@ -51,0 +54,0 @@ |
@@ -7,2 +7,3 @@ 'use strict' | ||
const baseFilename = `${__dirname}/fixtures/test_${crypto.randomBytes(16).toString('hex')}` | ||
const { fork } = require('child_process') | ||
@@ -469,1 +470,11 @@ const t = require('tap') | ||
}) | ||
test('crash on unhandled rejection', t => { | ||
t.plan(1) | ||
const argv = [ '-p', getPort(), './test/data/rejection.js' ] | ||
const child = fork(path.join(__dirname, '..', 'start.js'), argv, { silent: true }) | ||
child.on('close', function (code) { | ||
t.strictEqual(code, 1) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
46571
35
1128
213
15
3
+ Addedmake-promises-safe@^1.1.0
+ Addedmake-promises-safe@1.1.0(transitive)