Last active
April 17, 2019 15:50
-
-
Save dbauszus-glx/e007240929c593bb92423b96099ac3d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set jsrender module for server-side templates. | |
const jsr = require('jsrender'); | |
module.exports = {route, view}; | |
function route(fastify) { | |
fastify.route({ | |
method: 'GET', | |
url: '/', | |
preValidation: fastify.auth([ | |
(req, res, next) => fastify.authToken(req, res, next, { | |
public: global.public, | |
login: true | |
}) | |
]), | |
handler: view | |
}); | |
fastify.route({ | |
method: 'POST', | |
url: '/', | |
handler: (req, res) => fastify.login.post(req, res, { | |
view: view | |
}) | |
}); | |
}; | |
function view(req, res, token = { access: 'public' }) { | |
// Build the template with jsrender and send to client. | |
res | |
.type('text/html') | |
.send( | |
jsr | |
.templates('./public/views/desktop.html') | |
.render({ token: token.signed || '""' }) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment