-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Marko support #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks good. Except, I don't see how templates could be modified during development and reloaded without completely restarting the server since they are cached. |
@delvedor ah yes, it's early and I didn't quite parse the way that is working. Looks good. FYI, and I know it is generic for multiple "engines", but Marko stuff shouldn't be stored in the cache at all. It is already cached by Node's internal |
@jsumners let me understand, the load api read the template file just one time and then it uses a cache? |
@delvedor yes, depending on configuration passed into the Marko engine. In short, once Marko has compiled a template it |
@jsumners ah ok, but how can marko know when I've changed the original template? |
By passing in the right configuration to Marko: That should be settable via the options passed in to Marko. But it doesn't seem to be documented in the new docs. I'll have to file a bug report on that one. The old docs are at http://v3.markojs.com/docs/marko/get-started/#hot-reloading-templates |
@jsumners ok, so your suggestion is do something like this, right? :) function viewMarko (page, data, opts) {
if (!page || !data) {
this.send(new Error('Missing data'))
return
}
const template = engine.load(join(templatesDir, page))
if (opts && opts.stream) {
this.send(template.stream(data))
} else {
template.renderToString(data, send(this))
}
function send (that) {
return function _send (err, html) {
if (err) return that.send(err)
that.header('Content-Type', 'text/html').send(html)
}
}
} @patrick-steele-idem any suggestion? :) |
Nice job on fastify! I'm definitely a fan of minimalist server-side web frameworks that are optimized for speed. Regarding Marko integration, the following pattern is what I would recommend for Marko if we could make it work: const fastify = require('fastify')()
const template = require('./path/to/template.marko'); // The `.marko` extension is optional, but added here for clarity
fastify.get('/', (req, reply) => {
template.render(reply.res, { text: 'text' }); // res would be the raw writable HTTP response stream and marko will automatically end the response when it done
// OR, if we were allowed to monkey-patch the `reply` prototype some how:
reply.marko(template, { text: 'text' });
})
fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
}) With this approach, the Also, for reference: Express + Marko Thoughts? |
That's basically my original statement @patrick-steele-idem -- @delvedor I was just trying to make you aware of the way Marko works since you are implementing a cache in the plugin. If you think adding special cases for specific engines is acceptable, then your suggestion looks good to me. |
@patrick-steele-idem thank you! :)
decorate
Indeed, @jsumners yeah, I was not aware of the marko cache, so in this case |
As titled.
The benchmark are very promising, with
Marko
we gain at least 1000 request per second compared toejs
:)Feedbacks?
cc @mcollina @jsumners @patrick-steele-idem