-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (41 loc) · 977 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
import fp from 'fastify-plugin'
import pollRoute from './routes/main/post.js'
import getJobRoute from './routes/main/get.js'
import queueJobRoute from './routes/job/post.js'
import deleteJobRoute from './routes/main/delete.js'
export const defaultOptions = {
getJob: () => null,
getJobData: () => ({}),
queueJob: () => false,
deleteJob: () => false
}
async function fastifyCloudPrnt (fastify, options = defaultOptions) {
const {
getJob,
getJobData,
queueJob,
deleteJob,
routePrefix
} = {
...defaultOptions,
...options
}
fastify.decorate('cloudPrnt', {
getJob,
getJobData,
queueJob,
deleteJob
})
fastify.register(async function (f) {
f.route(pollRoute)
f.route(getJobRoute)
f.route(queueJobRoute)
f.route(deleteJobRoute)
}, { prefix: routePrefix })
}
export default fp(fastifyCloudPrnt, {
name: 'fastify-plugin',
decorators: ['view'],
dependencies: ['@fastify/view']
})