Skip to content

Instantly share code, notes, and snippets.

View delvedor's full-sized avatar
🏠
Working from home

Tomas Della Vedova delvedor

🏠
Working from home
View GitHub Profile
import Fastify from 'fastify'
import { TypeBoxTypeProvider, Type } from 'fastify-type-provider-typebox'
const fastify = Fastify({
ajv: {
customOptions: {
strict: 'log',
keywords: ['kind', 'modifier']
}
}
import Fastify from 'fastify'
const fastify = Fastify({
logger: {
transport: {
target: 'pino-pretty',
options: { destination: 1 }
}
}
})
import Fastify from 'fastify'
const fastify = Fastify()
fastify.register(async fastify => {
fastify.setErrorHandler(async err => {
console.log(err.message) // 'kaboom'
throw new Error('caught')
})
@delvedor
delvedor / blinksh-snazzy.js
Created July 5, 2021 12:33
A snazzy theme from Sindresorhus for Blink.sh
black = '#97979b';
red = '#ff5c57';
green = '#5af78e';
yellow = '#f3f99d';
blue = '#57c7ff';
magenta = '#ff6ac1';
cyan = '#9aedfe';
white = '#f1f1f0';
lightBlack = '#686868';
lightRed = red;

With content length header

Node 10

  • keep alive:
    • data
    • request timeout
    • (request hanging for a while)
    • end
    • finished
  • close
Framework Version Router? Requests/sec
Express 4.17.1 15,978
hapi 19.1.0 45,815
Restify 8.5.1 49,279
Koa 2.13.0 54,848
Fastify 3.0.0 78,956
-
http.Server 12.18.2 70,380
@delvedor
delvedor / bio.md
Last active July 18, 2019 14:51
Speaker Bio

Tomas is an enthusiastic software engineer, who spends most of his time programming in JavaScript and Node.js. He works for Elastic as Senior Software Engineer in the clients team, focusing on the JavaScript client. Tomas is also the author of the Fastify web framework and part of its ecosystem. He constantly forwards the enrichment of his knowledge and the exploration of new technologies; moreover, he is a strong Open Source supporter and he will always be passionate about technology, design, and music.

Handles:

### testing the login service
curl \
-H "Content-Type: application/json" \
-X POST -d '{"username":"john","password":"secret"}' \
http://localhost:3000/signup
### testing the post service
# create a new moo
curl \
-H "Content-Type: application/json" \
const fastify = require('fastify')()
fastify.get('/', async (request, reply) => {
return { hello: 'world' }
})
fastify.get('/callbacks', (request, reply) => {
reply.send({ hello: 'world' })
})
@delvedor
delvedor / accept-router.js
Created November 18, 2017 17:08
Routing based on the accept header
'use strict'
const assert = require('assert')
const Router = require('find-my-way')
const semver = require('semver')
function AcceptRouter (opts) {
if (!(this instanceof AcceptRouter)) {
return new AcceptRouter(opts)
}