Skip to content

Commit

Permalink
docs(examples): use console.log to log address (fastify#3048)
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS authored May 2, 2021
1 parent 7d9b587 commit 32413d6
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 25 deletions.
3 changes: 1 addition & 2 deletions examples/asyncawait.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: true })

const schema = {
schema: {
Expand Down Expand Up @@ -33,5 +33,4 @@ fastify

fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: false })

const opts = {
schema: {
Expand Down Expand Up @@ -41,5 +41,4 @@ fastify.listen(3000, function (err) {
if (err) {
throw err
}
console.log(`server listening on ${fastify.server.address().port}`)
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: false })

const opts = {
schema: {
Expand Down Expand Up @@ -49,5 +49,4 @@ fastify.listen(3000, function (err) {
if (err) {
throw err
}
console.log(`server listening on ${fastify.server.address().port}`)
})
30 changes: 30 additions & 0 deletions examples/benchmark/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

const fastify = require('../fastify')({
logger: false
})

const schema = {
schema: {
response: {
200: {
type: 'object',
properties: {
hello: {
type: 'string'
}
}
}
}
}
}

fastify
.get('/', schema, function (req, reply) {
reply
.send({ hello: 'world' })
})

fastify.listen(3000, (err, address) => {
if (err) throw err
})
3 changes: 1 addition & 2 deletions examples/hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: true })

const opts = {
schema: {
Expand Down Expand Up @@ -85,5 +85,4 @@ fastify.listen(3000, function (err) {
if (err) {
throw err
}
console.log(`server listening on ${fastify.server.address().port}`)
})
4 changes: 2 additions & 2 deletions examples/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const fastify = require('../fastify')({
https: {
key: fs.readFileSync(path.join(__dirname, '../test/https/fastify.key')),
cert: fs.readFileSync(path.join(__dirname, '../test/https/fastify.cert'))
}
},
logger: true
})

const opts = {
Expand All @@ -33,5 +34,4 @@ fastify

fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
4 changes: 2 additions & 2 deletions examples/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const fastify = require('../fastify')({
https: {
key: fs.readFileSync(path.join(__dirname, '../test/https/fastify.key')),
cert: fs.readFileSync(path.join(__dirname, '../test/https/fastify.cert'))
}
},
logger: true
})

const opts = {
Expand All @@ -32,5 +33,4 @@ fastify

fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
3 changes: 1 addition & 2 deletions examples/parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: true })
const jsonParser = require('fast-json-body')
const qs = require('qs')

Expand Down Expand Up @@ -38,5 +38,4 @@ fastify

fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
3 changes: 1 addition & 2 deletions examples/route-prefix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: true })

const opts = {
schema: {
Expand Down Expand Up @@ -35,5 +35,4 @@ fastify.listen(8000, function (err) {
if (err) {
throw err
}
console.log(`server listening on ${fastify.server.address().port}`)
})
3 changes: 1 addition & 2 deletions examples/shared-schema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: true })

fastify.addSchema({
$id: 'https://foo/common.json',
Expand Down Expand Up @@ -33,5 +33,4 @@ fastify

fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
1 change: 0 additions & 1 deletion examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ fastify

fastify.listen(3000, (err, address) => {
if (err) throw err
fastify.log.info(`server listening on ${address}`)
})
2 changes: 1 addition & 1 deletion examples/simple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { fastify } from '../fastify.js'

const app = fastify({
logger: false
logger: true
})

const schema = {
Expand Down
3 changes: 1 addition & 2 deletions examples/typescript-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const server: FastifyInstance<
Server,
IncomingMessage,
ServerResponse
> = fastify();
> = fastify({ logger: true });

// Define interfaces for our request. We can create these automatically
// off our JSON Schema files (See TypeScript.md) but for the purpose of this
Expand Down Expand Up @@ -75,5 +75,4 @@ server.listen(8080, (err, address) => {
console.error(err);
process.exit(0);
}
console.log(`Server listening at ${address}`);
});
3 changes: 1 addition & 2 deletions examples/use-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fastify = require('../fastify')()
const fastify = require('../fastify')({ logger: true })

const opts = {
schema: {
Expand All @@ -22,5 +22,4 @@ fastify.listen(3000, function (err) {
if (err) {
throw err
}
console.log(`server listening on ${fastify.server.address().port}`)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "fastify.d.ts",
"scripts": {
"bench": "branchcmp -r 2 -g -s \"npm run benchmark\"",
"benchmark": "npx concurrently -k -s first \"node ./examples/simple.js\" \"npx autocannon -c 100 -d 5 -p 10 localhost:3000/\"",
"benchmark": "npx concurrently -k -s first \"node ./examples/benchmark/simple.js\" \"npx autocannon -c 100 -d 5 -p 10 localhost:3000/\"",
"coverage": "npm run unit -- --cov --coverage-report=html",
"license-checker": "license-checker --production --onlyAllow=\"MIT;ISC;BSD-3-Clause;BSD-2-Clause\"",
"lint": "npm run lint:standard && npm run lint:typescript",
Expand Down

0 comments on commit 32413d6

Please sign in to comment.