Skip to content

Commit afaa048

Browse files
authored
feat: renamed fastify instance to app closes #9 (#10)
Signed-off-by: dan.castillo <[email protected]>
1 parent e7b85c5 commit afaa048

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

snippets/snippets-js.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"scope": "javascript,typescript",
44
"prefix": "ffhello",
55
"body": [
6-
"const fastify = require('fastify')({ logger: true })",
7-
"fastify.get('/', async (request, reply) => {",
6+
"const app = require('fastify')({ logger: true })",
7+
"app.get('/', async (request, reply) => {",
88
" return { hello: 'world' }",
99
"})",
10-
"fastify.post('/', async (request, reply) => {",
10+
"app.post('/', async (request, reply) => {",
1111
" return request.body",
1212
"})",
13-
"fastify.listen(8080)"
13+
"app.listen({ port: 8080 })"
1414
],
1515
"description": "Create an hello world server"
1616
},
@@ -21,7 +21,7 @@
2121
"ffplugin"
2222
],
2323
"body": [
24-
"fastify.register(function plugin (instance, opts, next) {",
24+
"app.register(function plugin (app, opts, next) {",
2525
" next()",
2626
"})"
2727
],
@@ -31,8 +31,8 @@
3131
"scope": "javascript,typescript",
3232
"prefix": "ffprintroutes",
3333
"body": [
34-
"fastify.ready(() => {",
35-
" console.log(fastify.printRoutes())",
34+
"app.ready(() => {",
35+
" console.log(app.printRoutes())",
3636
"})"
3737
],
3838
"description": "Print to stdout the routes tree"
@@ -43,7 +43,7 @@
4343
"fferrorhandler"
4444
],
4545
"body": [
46-
"fastify.setErrorHandler(function (error, request, reply) {",
46+
"app.setErrorHandler(function (error, request, reply) {",
4747
" this.log.error(error)",
4848
" reply.status(500).send({ ok: false })",
4949
"})"
@@ -56,7 +56,7 @@
5656
"ffdecorateserver"
5757
],
5858
"body": [
59-
"fastify.decorate('utility', function () {",
59+
"app.decorate('utility', function () {",
6060
" ${TM_SELECTED_TEXT:${0}}",
6161
"})"
6262
],
@@ -68,7 +68,7 @@
6868
"ffdecoraterequest"
6969
],
7070
"body": [
71-
"fastify.decorateRequest('utility', function () {",
71+
"app.decorateRequest('utility', function () {",
7272
" ${TM_SELECTED_TEXT:${0}}",
7373
"})"
7474
],
@@ -80,7 +80,7 @@
8080
"ffdecoratereply"
8181
],
8282
"body": [
83-
"fastify.decorateReply('utility', function () {",
83+
"app.decorateReply('utility', function () {",
8484
" ${TM_SELECTED_TEXT:${0}}",
8585
"})"
8686
],
@@ -93,7 +93,7 @@
9393
"hookonrequest"
9494
],
9595
"body": [
96-
"fastify.addHook('onRequest', function hook (request, reply, done) {",
96+
"app.addHook('onRequest', function hook (request, reply, done) {",
9797
" ${TM_SELECTED_TEXT:${0}}",
9898
" done()",
9999
"})"
@@ -107,7 +107,7 @@
107107
"hookpreparsing"
108108
],
109109
"body": [
110-
"fastify.addHook('preParsing', function hook (request, reply, payload, done) {",
110+
"app.addHook('preParsing', function hook (request, reply, payload, done) {",
111111
" const newPayload = $0",
112112
" done(null, newPayload)",
113113
"})"
@@ -121,7 +121,7 @@
121121
"hookprevalidation"
122122
],
123123
"body": [
124-
"fastify.addHook('preValidation', function hook (request, reply, done) {",
124+
"app.addHook('preValidation', function hook (request, reply, done) {",
125125
" // request's fields are not been validated yet by the JSON Schema",
126126
" done()",
127127
"})"
@@ -135,7 +135,7 @@
135135
"hookprehandler"
136136
],
137137
"body": [
138-
"fastify.addHook('preHandler', function hook (request, reply, done) {",
138+
"app.addHook('preHandler', function hook (request, reply, done) {",
139139
" $0",
140140
" done(null)",
141141
"})"
@@ -149,7 +149,7 @@
149149
"hookpreserialization"
150150
],
151151
"body": [
152-
"fastify.addHook('preSerialization', function hook (request, reply, payload, done) {",
152+
"app.addHook('preSerialization', function hook (request, reply, payload, done) {",
153153
" // the hook is NOT called if the payload is a string, a Buffer, a stream or null.",
154154
" const newPayload = $0",
155155
" done(null, newPayload)",
@@ -164,7 +164,7 @@
164164
"hookonerror"
165165
],
166166
"body": [
167-
"fastify.addHook('onError', function hook (request, reply, error, done) {",
167+
"app.addHook('onError', function hook (request, reply, error, done) {",
168168
" // Notice: unlike the other hooks, pass an error to the done function is not supported.",
169169
" done()",
170170
"})"
@@ -178,7 +178,7 @@
178178
"hookonsend"
179179
],
180180
"body": [
181-
"fastify.addHook('onSend', function hook (request, reply, payload, done) {",
181+
"app.addHook('onSend', function hook (request, reply, payload, done) {",
182182
" // If you change the payload, you may only change it to a string, a Buffer, a stream, or null.",
183183
" const newPayload = $0",
184184
" done(null, newPayload)",
@@ -193,7 +193,7 @@
193193
"hookonresponse"
194194
],
195195
"body": [
196-
"fastify.addHook('onResponse', function hook (request, reply, done) {",
196+
"app.addHook('onResponse', function hook (request, reply, done) {",
197197
" // The onResponse hook is executed when a response has been sent",
198198
" done()",
199199
"})"
@@ -207,7 +207,7 @@
207207
"hookontimeout"
208208
],
209209
"body": [
210-
"fastify.addHook('onTimeout', function hook (request, reply, done) {",
210+
"app.addHook('onTimeout', function hook (request, reply, done) {",
211211
" // The onTimeout hook is executed when a request is timed out and the http socket has been hanged up",
212212
" done()",
213213
"})"
@@ -221,7 +221,7 @@
221221
"hookonready"
222222
],
223223
"body": [
224-
"fastify.addHook('onReady', function hook (done) {",
224+
"app.addHook('onReady', function hook (done) {",
225225
" done(null)",
226226
"})"
227227
],
@@ -234,7 +234,7 @@
234234
"hookonclose"
235235
],
236236
"body": [
237-
"fastify.addHook('onClose', function hook (instance done) {",
237+
"app.addHook('onClose', function hook (app, done) {",
238238
" done()",
239239
"})"
240240
],
@@ -247,7 +247,7 @@
247247
"hookonroute"
248248
],
249249
"body": [
250-
"fastify.addHook('onRoute', function hook (routeOptions) {",
250+
"app.addHook('onRoute', function hook (routeOptions) {",
251251
" // routeOptions.method",
252252
" // routeOptions.schema",
253253
" // routeOptions.url",
@@ -269,7 +269,7 @@
269269
"hookonregister"
270270
],
271271
"body": [
272-
"fastify.addHook('onRegister', function hook (instance, opts) {",
272+
"app.addHook('onRegister', function hook (app, opts) {",
273273
" // The hook will be executed before the registered code",
274274
"})"
275275
],
@@ -284,7 +284,7 @@
284284
"ffschema"
285285
],
286286
"body": [
287-
"fastify.addSchema($0)"
287+
"app.addSchema($0)"
288288
],
289289
"description": "Add a shared JSON schema to fastify"
290290
},
@@ -295,7 +295,7 @@
295295
"ff404"
296296
],
297297
"body": [
298-
"fastify.setNotFoundHandler(function basic404(request, reply) {",
298+
"app.setNotFoundHandler(function basic404(request, reply) {",
299299
" const { url, method } = request.raw",
300300
" const message = `Route ${method}:${url} not found`",
301301
" request.log.info(message)",
@@ -308,4 +308,4 @@
308308
],
309309
"description": "Add the default 404 not found handler"
310310
}
311-
}
311+
}

0 commit comments

Comments
 (0)