Skip to content package
fastify-early-hints v0.0.3 Fastify Early Hints
node any 2 deps cjs types open source
overview readme
license MIT
deps 2
unpacked 67.6 kB
files 24
node any $ npm install fastify-early-hints@0.0.3n npmREADME GitHub-flavored package documentation.
downloads Across all versions.
Download trend unavailable.
compatibility Runtime metadata.
versions Latest published Nov 17, 2020
maintainers Registry package owners.
install size Estimated unpacked size across 3 packages.
123.1 kB
Includes dependencies.
dependencies 2 direct · 1 outdated
contents Fastify Early Hints
Draft proposal of plugin handling the HTTP 103 code.
Based on : https://github.com/fastify/fastify/issues/2683
Install
npm i fastify-early-hints copy
Usage
eh.add: Every call writes to the socket and returns a promise. Altought all the promises created throught the reply lifecycle are awaited in the onSend hook.
const Fastify = require ( "fastify" );
const eh = require ( "fastify-early-hints" );
const fastify = Fastify ({ logger: true });
fastify. register (eh);
fastify. get ( "/" , async (request, reply) => {
reply.eh. add ([
"Link: </style.css>; rel=preload; as=style" ,
"Link: </script.js>; rel=preload; as=script" ,
]);
await reply.eh. add ([
{ href: "//example.com" , rel: "preload" , as: "style" },
{ href: "//example.com" , rel:
Result
$ curl -D - http://localhost:3000
HTTP/1.1 103 Early Hints
Link: </style.css>; rel=preload; as=style
Link: </script.js>; rel=preload; as=script
HTTP/1.1 103 Early Hints
Link: </style.css>; rel=preload; as=style
Link: </script.js>; rel=preload; as=script
Link: <//example.com>; rel=preload; as=style
Link: <//example.com>; rel=preload; as=style; crossorigin
Link: <//example.com>; rel=preconnect
Link: <//example2.com>; rel=preconnect; crossorigin
Link: <//example3.com>; rel=preconnect; crossorigin=use-credentials
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
content-length: 17
Date: Thu, 12 Nov 2020 22:45:54 GMT
Connection: keep-alive
{"hello":"world"} copy
Todo
Handling different cases combinations
improve tests
References
License
Licensed under MIT .
"preload"
, as:
"style"
, cors:
true
},
{ href: "//example.com" , rel: "preconnect" },
{ href: "//example2.com" , rel: "preconnect" , cors: true },
{ href: "//example3.com" , rel: "preconnect" , cors: "use-credentials" },
]);
return { hello: "world" };
});
const start = async () => {
try {
await fastify. listen ( 3000 );
fastify.log. info ( `server listening on ${ fastify . server . address (). port }` );
} catch (err) {
fastify.log. error (err);
process. exit ( 1 );
}
};
start ();
copy