11
22# Node/Express GNU Clacks
33
4- A man is not dead while his name is still spoken. Add an 'X-Clacks-Overhead' Header to your Node/ Express app.
4+ A man is not dead while his name is still spoken. Add an 'X-Clacks-Overhead' Header to your vanilla Node or Express app.
55
66See [ http://www.gnuterrypratchett.com ] ( http://www.gnuterrypratchett.com " GNU Terry Pratchett ")
77
@@ -16,22 +16,50 @@ npm install node-gnu-clacks --save
1616```
1717
1818## Usage
19- - Import the module and tell your app to use as middleware.
19+ - Import the module and tell your app to use as middleware:
20+
21+ ``` js
22+ const { node: gnuHeaderNode } = require (' node-gnu-clacks' );
23+ const { express: gnuHeaderExpress } = require (' node-gnu-clacks' );
24+ ```
25+
26+ _ note: you can also use ` const gnuHeader = require('node-gnu-clacks'); ` for express apps for backwards compatibility with v1._
2027
2128## Options
22- - Optionally, add an array of names to be passed along with the default, 'Terry Pratchett'.
29+ ** string[ ] ghosts = [ 'Terry Pratchett'] **
30+
31+ Add an array of names to be passed. This is in addition to the default, 'Terry Pratchett', which will always be added.
2332
24- ## Example
33+ ## Example with a vanilla Node app
2534
2635``` js
36+ const http = require (' http' );
37+ const { node: gnuHeaderNode } = require (' node-gnu-clacks' );
2738
28- const express = require (' express' );
29- const gnuHeader = require (' node-gnu-clacks' );
39+ http .createServer ((req , res ) => {
40+ const addClacksHeader = gnuHeaderNode ([' Moist' , ' Adora' , ' Reacher' ]);
41+ addClacksHeader (res);
42+
43+ res .writeHead (200 , {' Content-Type' : ' text/plain' });
44+ res .end (' A man is not dead while his name is still spoken.\n ' );
45+ }).listen (3000 );
46+ ```
47+
48+ ## Example with an Express app
49+
50+ ``` js
51+ const express = require (' lib/express' );
52+ const { express: gnuHeaderExpress } = require (' node-gnu-clacks' );
3053
3154const app = express ();
3255
33- app .use (gnuHeader ());
56+ app .use (gnuHeaderExpress ());
3457or
35- app .use (gnuHeader ([' Moist' , ' Adora' , ' Reacher' ]));
58+ app .use (gnuHeaderExpress ([' Moist' , ' Adora' , ' Reacher' ]));
59+
60+ app .get (' /' , (req , res ) => {
61+ res .send (' A man is not dead while his name is still spoken.' );
62+ });
3663
64+ app .listen (3000 );
3765```
0 commit comments