history.js 796 B

12345678910111213141516171819202122
  1. import { Elysia } from 'elysia'
  2. import { Eta } from "eta"
  3. import Meteostanica from '../../utils/meteostanica'
  4. const eta = new Eta({ views: "./templates" })
  5. export default (langName, lang) => new Elysia({ prefix: `/history` })
  6. .get('/', ({ set }) => {
  7. set.headers['content-type'] = 'text/html; charset=utf8'
  8. return eta.render(`${langName}/history/index`, { })
  9. })
  10. .get(`/:property`, ({ params: { property }, set }) => {
  11. const data = Meteostanica.getDataProperty(property)
  12. if (!data) {
  13. set.headers['content-type'] = 'text/html; charset=utf8'
  14. return eta.render(`${langName}/history/notFound`, { property })
  15. }
  16. set.headers['content-type'] = 'text/html; charset=utf8'
  17. return eta.render(`${langName}/history/property`, { lang, property, data })
  18. })