-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 787 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
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */
/* eslint-disable import/extensions */
import Fastify from 'fastify';
import cron from 'node-cron';
import fastifyCors from 'fastify-cors';
import scraper, { getJobPosts } from './scraper.js';
cron.schedule('0 0 * * 0', () => {
console.log(`Cron execution: ${new Date()}`);
getJobPosts();
});
const fastify = Fastify({
logger: true,
});
fastify.register(fastifyCors, {
origin: '*',
});
fastify.get('/', (request, reply) => {
reply.send({ message: 'Scraper for hacker news whoishiring' });
});
fastify.route({ method: 'GET', url: '/whoishiring/jobs', handler: scraper });
fastify.listen(3001, '0.0.0.0', (err) => {
if (err) {
fastify.log.error(err);
process.exit(1);
}
});