-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrender.js
24 lines (23 loc) · 900 Bytes
/
render.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
import { call, complement, compose, ifElse, isNil, path, pipe } from 'ramda'
import { DEFAULT_JOB_OPTIONS } from '../../../queue'
// default :: (Configuration, Logger, Queue, RequestRegistry) -> Express.app -> Express.app
export default (configuration, logger, queue, requestRegistry) => app =>
app.get('/render', (req, res, next) => call(pipe(
() => logger.debug(`Render request for url "${req.query.url}" started.`),
ifElse(
() => compose(complement(isNil), path(['query', 'url']))(req),
pipe(
() => requestRegistry.add(req, res, next),
jobId => queue.add({
type: 'html',
url: req.query.url,
queuedAt: Date.now(),
}, {
...DEFAULT_JOB_OPTIONS,
timeout: configuration.queue.job.timeout,
jobId,
}),
),
() => res.status(400).end('Missing url query parameter.'),
),
)))