-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (36 loc) · 984 Bytes
/
server.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
const fastify = require('fastify')({ logger: true })
var getCronString = require('@darkeyedevelopers/natural-cron.js')
const INVALID_CRON = "* * * * ? *"
const PORT = process.env.port || 3000
fastify.route({
method: 'GET',
url: '/',
schema: {
querystring: {
type: 'object',
properties: {
schedule: { type: 'string' }
},
required: ['schedule'],
},
response: {
200: {
type: 'object',
properties: {
cron: { type: 'string'}
},
},
},
},
handler: async (request, reply) => {
let cron = getCronString(request.query.schedule)
if (cron === INVALID_CRON) reply.code(400).send()
else reply.code(200).send(cron)
}
})
fastify.listen({ host: "0.0.0.0", port: PORT }, (err) => {
if (err) {
fastify.log.error(err)
process.exit(1)
}
})