routes.js 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import express from 'express';
  2. import path from 'path';
  3. import fs from 'fs';
  4. import React from 'react';
  5. import Index from '../src/js/components/Index';
  6. import GameInterface from '../src/js/components/GameInterface';
  7. const router = express.Router();
  8. router.get('/', (req, res) => {
  9. res.render('index', {
  10. content: React.renderToString(<Index io={{}} />)
  11. });
  12. });
  13. router.get('/about', (req, res) => {
  14. res.render('about');
  15. });
  16. router.get('/play/:token/:time/:inc', (req, res) => {
  17. let params = [
  18. req.params.token,
  19. req.params.time,
  20. req.params.inc
  21. ];
  22. res.render('play', {
  23. content: React.renderToString(<GameInterface params={params} io={{}} />)
  24. });
  25. });
  26. router.get('/logs', (req, res) => {
  27. fs.readFile(path.join(__dirname, '../logs/games.log'), (err, data) => {
  28. if (err) {
  29. return res.redirect('/');
  30. }
  31. res.set('Content-Type', 'text/plain');
  32. res.send(data);
  33. });
  34. });
  35. export default router;