Status page for GenSoc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

37 lines
1.2 KiB

  1. import * as Express from 'express';
  2. import * as ejs from 'ejs';
  3. import * as R from 'ramda';
  4. import getMumbleStatus from 'src/lib/mumble';
  5. import getMastodonStatus from 'src/lib/mastodon';
  6. import inMemoryCache from '@nrk/nodecache-as-promised'
  7. import getXMPPStatus from './lib/xmpp';
  8. const cache = inMemoryCache({ initial: {}, maxAge: 60000 });
  9. const app = Express();
  10. const updateMastodonStatus = () => getMastodonStatus('https://gensokyo.social');
  11. const updateMumbleStatus = () => getMumbleStatus('gensokyo.social');
  12. const updateXMPPStatus = () => getXMPPStatus('gensokyo.social');
  13. const getFromCache = () => Promise.all([
  14. cache.get('mastodonStatus', { worker: updateMastodonStatus, ttl: 60000 }),
  15. cache.get('mumbleStatus', { worker: updateMumbleStatus, ttl: 60000 }),
  16. cache.get('XMPPStatus', { worker: updateXMPPStatus, ttl: 60000 }),
  17. ]).then(R.map(val => val.value));
  18. app.get('/', (_, res) => {
  19. getFromCache().then(([mastodonStatus, mumbleStatus, XMPPStatus]) => {
  20. ejs.renderFile('./src/templates/index.ejs', { mastodonStatus, mumbleStatus, XMPPStatus}, {}, (err, str) => {
  21. res.status(200).send(str);
  22. });
  23. })
  24. });
  25. app.listen(8080, () => {
  26. console.log('listening on 8080')
  27. });