The frontend/UI server, written in JS using the MarkoJS library
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.

36 lines
751 B

6 years ago
6 years ago
6 years ago
  1. module.exports = (req, res, next) => {
  2. if (res.marko) {
  3. res.markoAsync = async(template, input) => {
  4. const locals = Object.assign((res.locals || {}), input)
  5. try {
  6. for (const key in locals) {
  7. const value = locals[key]
  8. if (value instanceof Promise) {
  9. locals[key] = await value
  10. }
  11. }
  12. } catch(err) {
  13. if (JSON.stringify(err) === "{}") {
  14. return next(err)
  15. }
  16. return res.status(404).json(err)
  17. }
  18. return res.marko(template, locals)
  19. }
  20. }
  21. if (req.user) {
  22. res.locals.user = {
  23. loggedIn: true,
  24. name: req.user._json.name,
  25. }
  26. } else {
  27. res.locals.user = {
  28. loggedIn: false,
  29. }
  30. }
  31. next()
  32. }