-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (31 loc) · 948 Bytes
/
app.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
const bus_cache = require('./bus/scripts/caching')
const mrt_cache = require('./train/scripts/caching')
const path = require('path');
const fastify = require('fastify')({
logger: true
})
fastify.get('/', async (request, reply) => {
return reply.redirect(302, "https://github.com/Ju-Long/sgTransport")
});
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'assets'),
prefix: '/assets/'
});
fastify.register(require('./bus/index'))
fastify.register(require('./train/index'))
const start = async () => {
await fastify.listen(3002, '0.0.0.0')
.then((address) => console.log(`server is listening on ${address}`))
.catch(err => {
console.log('error starting server: ', err);
process.exit(1);
});
}
start()
// MARK: CRON JOBS
const cron = require('node-cron')
// fetch Everyday
cron.schedule('0 0 * * *', async () => {
await bus_cache.cache()
await mrt_cache.cache()
})