Giter Site home page Giter Site logo

fastify / point-of-view Goto Github PK

View Code? Open in Web Editor NEW
319.0 20.0 85.0 531 KB

Template rendering plugin for Fastify

License: MIT License

JavaScript 97.00% HTML 0.16% TypeScript 1.65% Liquid 0.06% Handlebars 0.11% Twig 0.05% Pug 0.05% Mustache 0.07% EJS 0.69% Nunjucks 0.16%
fastify templates speed fastify-plugin

point-of-view's Introduction

@fastify/view

CI NPM version js-standard-style

Templates rendering plugin support for Fastify.

@fastify/view decorates the reply interface with the view and viewAsync methods for managing view engines, which can be used to render templates responses.

Currently supports the following templates engines:

In production mode, @fastify/view will heavily cache the templates file and functions, while in development will reload every time the template file and function.

Note: For Fastify v3 support, please use point-of-view 5.x (npm i point-of-view@5).

Note that at least Fastify v2.0.0 is needed.

Recent Changes

Note: reply.viewAsync added as a replacement for reply.view and fastify.view. See Migrating from view to viewAsync.

Note: ejs-mate support has been dropped.

Note: marko support has been dropped. Please use @marko/fastify instead.

Benchmarks

The benchmark were run with the files in the benchmark folder with the ejs engine. The data has been taken with: autocannon -c 100 -d 5 -p 10 localhost:3000

  • Express: 8.8k req/sec
  • Fastify: 15.6k req/sec

Install

npm i @fastify/view

Quick start

fastify.register is used to register @fastify/view. By default, It will decorate the reply object with a view method that takes at least two arguments:

  • the template to be rendered
  • the data that should be available to the template during rendering

This example will render the template using the EJS engine and provide a variable name to be used inside the template:

<!-- index.ejs --->
<!DOCTYPE html>
<html lang="en">
  <head></head>
  <body>
    <p>Hello, <%= name %>!</p>
  </body>
</html>
// index.js:
const fastify = require("fastify")()
const fastifyView = require("@fastify/view")

fastify.register(fastifyView, {
  engine: {
    ejs: require("ejs")
  }
})

// synchronous handler:
fastify.get("/", (req, reply) => {
  reply.view("index.ejs", { name: "User" });
})

// asynchronous handler:
fastify.get("/", async (req, reply) => {
  return reply.viewAsync("index.ejs", { name: "User" });
})

fastify.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log(`server listening on ${fastify.server.address().port}`);
})

Configuration

Options

Option Description Default
engine Required. The template engine object - pass in the return value of require('<engine>')
production Enables caching of template files and render functions NODE_ENV === "production"
maxCache In production mode, maximum number of cached template files and render functions 100
defaultContext Template variables available to all views. Variables provided on render have precedence and will override this if they have the same name.

Example: { siteName: "MyAwesomeSite" }
{}
propertyName The property that should be used to decorate reply and fastify

E.g. reply.view() and fastify.view() where "view" is the property name
"view"
asyncPropertyName The property that should be used to decorate reply for async handler

Defaults to ${propertyName}Async if propertyName is defined
"viewAsync"
root The root path of your templates folder. The template name or path passed to the render function will be resolved relative to this path "./"
charset Default charset used when setting Content-Type header "utf-8"
includeViewExtension Automatically append the default extension for the used template engine if omitted from the template name . So instead of template.hbs, just template can be used false
viewExt Override the default extension for a given template engine. This has precedence over includeViewExtension and will lead to the same behavior, just with a custom extension.

Example: "handlebars"
""
layout See Layouts

This option lets you specify a global layout file to be used when rendering your templates. Settings like root or viewExt apply as for any other template file.

Example: ./templates/layouts/main.hbs
options See Engine-specific settings {}

Example

fastify.register(require("@fastify/view"), {
  engine: {
    handlebars: require("handlebars"),
  },
  root: path.join(__dirname, "views"), // Points to `./views` relative to the current file
  layout: "./templates/template", // Sets the layout to use to `./views/templates/layout.handlebars` relative to the current file.
  viewExt: "handlebars", // Sets the default extension to `.handlebars`
  propertyName: "render", // The template can now be rendered via `reply.render()` and `fastify.render()`
  defaultContext: {
    dev: process.env.NODE_ENV === "development", // Inside your templates, `dev` will be `true` if the expression evaluates to true
  },
  options: {}, // No options passed to handlebars
});

Layouts

@fastify/view supports layouts for EJS, Handlebars, Eta and doT. When a layout is specified, the request template is first rendered, then the layout template is rendered with the request-rendered html set on body.

Example

<!-- layout.ejs: -->
<!DOCTYPE html>
<html lang="en">
  <head></head>
  <body>
    <!--
      Ensure body is not escaped:

      EJS: <%- body %>
      Handlebars: {{{ body }}}
      ETA/doT: <%~ it.body %>
    -->
    <%- body %> 
    <br/>
  </body>
</html>
<!-- template.ejs: -->
<p><%= text %></p>
// index.js:
fastify.register(fastifyView, {
  engine: { ejs },
  layout: "layout.ejs"
})

fastify.get('/', (req, reply) => {
  const data = { text: "Hello!"}
  reply.view('template.ejs', data)
})

Providing a layout on render

Please note: Global layouts and providing layouts on render are mutually exclusive. They can not be mixed.

fastify.get('/', (req, reply) => {
  const data = { text: "Hello!"}
  reply.view('template.ejs', data, { layout: 'layout.ejs' })
})

Setting request-global variables

Sometimes, several templates should have access to the same request-specific variables. E.g. when setting the current username.

If you want to provide data, which will be depended on by a request and available in all views, you have to add property locals to reply object, like in the example below:

fastify.addHook("preHandler", function (request, reply, done) {
  reply.locals = {
    text: getTextFromRequest(request), // it will be available in all views
  };

  done();
});

Properties from reply.locals will override those from defaultContext, but not from data parameter provided to reply.view(template, data) function.

Rendering the template into a variable

The fastify object is decorated the same way as reply and allows you to just render a view into a variable (without request-global variables) instead of sending the result back to the browser:

// Promise based, using async/await
const html = await fastify.view("/templates/index.ejs", { text: "text" });

// Callback based
fastify.view("/templates/index.ejs", { text: "text" }, (err, html) => {
  // Handle error
  // Do something with `html`
});

If called within a request hook and you need request-global variables, see Migrating from view to viewAsync.

Registering multiple engines

Registering multiple engines with different configurations is supported. They are distinguished via their propertyName:

fastify.register(require("@fastify/view"), {
  engine: { ejs: ejs },
  layout: "./templates/layout-mobile.ejs",
  propertyName: "mobile",
});

fastify.register(require("@fastify/view"), {
  engine: { ejs: ejs },
  layout: "./templates/layout-desktop.ejs",
  propertyName: "desktop",
});

fastify.get("/mobile", (req, reply) => {
  // Render using the `mobile` render function
  return reply.mobile("/templates/index.ejs", { text: "text" });
});

fastify.get("/desktop", (req, reply) => {
  // Render using the `desktop` render function
  return reply.desktop("/templates/index.ejs", { text: "text" });
});

Minifying HTML on render

To utilize html-minifier-terser in the rendering process, you can add the option useHtmlMinifier with a reference to html-minifier-terser, and the optional htmlMinifierOptions option is used to specify the html-minifier-terser options:

// get a reference to html-minifier-terser
const minifier = require('html-minifier-terser')
// optionally defined the html-minifier-terser options
const minifierOpts = {
  removeComments: true,
  removeCommentsFromCDATA: true,
  collapseWhitespace: true,
  collapseBooleanAttributes: true,
  removeAttributeQuotes: true,
  removeEmptyAttributes: true
}
// in template engine options configure the use of html-minifier
  options: {
    useHtmlMinifier: minifier,
    htmlMinifierOptions: minifierOpts
  }

To filter some paths from minification, you can add the option pathsToExcludeHtmlMinifier with list of paths

// get a reference to html-minifier-terser
const minifier = require('html-minifier-terser')
// in options configure the use of html-minifier-terser and set paths to exclude from minification
const options = {
  useHtmlMinifier: minifier,
  pathsToExcludeHtmlMinifier: ['/test']
}

fastify.register(require("@fastify/view"), {
  engine: {
    ejs: require('ejs')
  },
  options
});

// This path is excluded from minification
fastify.get("/test", (req, reply) => {
  reply.view("./template/index.ejs", { text: "text" });
});

Engine-specific settings

Mustache

To use partials in mustache you will need to pass the names and paths in the options parameter:

  options: {
    partials: {
      header: 'header.mustache',
      footer: 'footer.mustache'
    }
  }
fastify.get('/', (req, reply) => {
  reply.view('./templates/index.mustache', data)
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.mustache', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      const render = mustache.render.bind(mustache, file)
      reply.view(render, data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.mustache', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

Handlebars

To use partials in handlebars you will need to pass the names and paths in the options parameter:

  options: {
    partials: {
      header: 'header.hbs',
      footer: 'footer.hbs'
    }
  }

You can specify compile options as well:

  options: {
    compileOptions: {
      preventIndent: true
    }
  }

To access defaultContext and reply.locals as @data variables:

  options: {
    useDataVariables: true
  }

To use layouts in handlebars you will need to pass the layout parameter:

fastify.register(require("@fastify/view"), {
  engine: {
    handlebars: require("handlebars"),
  },
  layout: "./templates/layout.hbs",
});

fastify.get("/", (req, reply) => {
  reply.view("./templates/index.hbs", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.hbs', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      const render = handlebars.compile(file)
      reply.view(render, data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.hbs', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

Nunjucks

You can load templates from multiple paths when using the nunjucks engine:

fastify.register(require("@fastify/view"), {
  engine: {
    nunjucks: require("nunjucks"),
  },
  templates: [
    "node_modules/shared-components",
    "views",
  ],
});

To configure nunjucks environment after initialization, you can pass callback function to options:

options: {
  onConfigure: (env) => {
    // do whatever you want on nunjucks env
  };
}
fastify.get('/', (req, reply) => {
  reply.view('./templates/index.njk', data)
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.njk', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      const render = nunjucks.compile(file)
      reply.view(render, data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.njk', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

Liquid

To configure liquid you need to pass the engine instance as engine option:

const { Liquid } = require("liquidjs");
const path = require('node:path');

const engine = new Liquid({
  root: path.join(__dirname, "templates"),
  extname: ".liquid",
});

fastify.register(require("@fastify/view"), {
  engine: {
    liquid: engine,
  },
});

fastify.get("/", (req, reply) => {
  reply.view("./templates/index.liquid", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.liquid', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      const render = engine.renderFile.bind(engine, './templates/index.liquid')
      reply.view(render, data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.liquid', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

doT

When using doT the plugin compiles all templates when the application starts, this way all .def files are loaded and both .jst and .dot files are loaded as in-memory functions. This behavior is recommended by the doT team here. To make it possible it is necessary to provide a root or templates option with the path to the template directory.

fastify.register(require("@fastify/view"), {
  engine: {
    dot: require("dot"),
  },
  root: "templates",
  options: {
    destination: "dot-compiled", // path where compiled .jst files are placed (default = 'out')
  },
});

fastify.get("/", (req, reply) => {
  // this works both for .jst and .dot files
  reply.view("index", { text: "text" });
});
const d = dot.process({ path: 'templates', destination: 'out' })
fastify.get('/', (req, reply) => {
  reply.view(d.index, data)
})
fastify.get('/', (req, reply) => {
  reply.view({ raw: readFileSync('./templates/index.dot'), imports: { def: readFileSync('./templates/index.def') } }, data)
})

eta

const { Eta } = require('eta')
let eta = new Eta()
fastify.register(pointOfView, {
  engine: {
    eta
  },
  templates: 'templates'
})

fastify.get("/", (req, reply) => {
  reply.view("index.eta", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.eta', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view(eta.compile(file), data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.eta', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

ejs

const ejs = require('ejs')
fastify.register(pointOfView, {
  engine: {
    ejs
  },
  templates: 'templates'
})

fastify.get("/", (req, reply) => {
  reply.view("index.ejs", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.ejs', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view(ejs.compile(file), data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.ejs', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

pug

const pug = require('pug')
fastify.register(pointOfView, {
  engine: {
    pug
  }
})


fastify.get("/", (req, reply) => {
  reply.view("index.pug", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.pug', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view(pug.compile(file), data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.pug', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

twig

const twig = require('twig')
fastify.register(pointOfView, {
  engine: {
    twig
  }
})


fastify.get("/", (req, reply) => {
  reply.view("index.twig", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.twig', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view(twig.twig({ data: file }), data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.twig', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

art

const art = require('art-template')
fastify.register(pointOfView, {
  engine: {
    'art-template': art
  }
})


fastify.get("/", (req, reply) => {
  reply.view("./index.art", { text: "text" });
});
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.art', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view(art.compile({ filename: path.join(__dirname, '..', 'templates', 'index.art') }), data)
    }
  })
})
fastify.get('/', (req, reply) => {
  fs.readFile('./templates/index.art', 'utf8', (err, file) => {
    if (err) {
      reply.send(err)
    } else {
      reply.view({ raw: file }, data)
    }
  })
})

Miscellaneous

Using @fastify/view as a dependency in a fastify-plugin

To require @fastify/view as a dependency to a fastify-plugin, add the name @fastify/view to the dependencies array in the plugin's opts.

fastify.register(myViewRendererPlugin, {
  dependencies: ["@fastify/view"],
});

Forcing a cache-flush

To forcefully clear cache when in production mode, call the view.clearCache() function.

fastify.view.clearCache();

Migrating from view to viewAsync

The behavior of reply.view is to immediately send the HTML response as soon as rendering is completed, or immediately send a 500 response with error if encountered, short-circuiting fastify's error handling hooks, whereas reply.viewAsync returns a promise that either resolves to the rendered HTML, or rejects on any errors. fastify.view has no mechanism for providing request-global variables, if needed. reply.viewAsync can be used in both sync and async handlers.

Sync handler

Previously:

fastify.get('/', (req, reply) => {
  reply.view('index.ejs', { text: 'text' })
})

Now:

fastify.get('/', (req, reply) => {
  return reply.viewAsync('index.ejs', { text: 'text' })
})

Async handler

Previously:

// This is an async function
fastify.get("/", async (req, reply) => {
  const data = await something();
  reply.view("/templates/index.ejs", { data });
  return
})

Now:

// This is an async function
fastify.get("/", async (req, reply) => {
  const data = await something();
  return reply.viewAsync("/templates/index.ejs", { data });
})

fastify.view (when called inside a route hook)

Previously:

// Promise based, using async/await
fastify.get("/", async (req, reply) => {
  const html = await fastify.view("/templates/index.ejs", { text: "text" });
  return html
})
// Callback based
fastify.get("/", (req, reply) => {
  fastify.view("/templates/index.ejs", { text: "text" }, (err, html) => {
    if(err) {
      reply.send(err)
    }
    else {
      reply.type("application/html").send(html)
    }
  });
})

Now:

// Promise based, using async/await
fastify.get("/", (req, reply) => {
  const html = await fastify.viewAsync("/templates/index.ejs", { text: "text" });
  return html
})
fastify.get("/", (req, reply) => {
  fastify.viewAsync("/templates/index.ejs", { text: "text" })
    .then((html) => reply.type("application/html").send(html))
    .catch((err) => reply.send(err))
  });
})

Note

By default views are served with the mime type text/html, with the charset specified in options. You can specify a different Content-Type header using reply.type.

Acknowledgements

This project is kindly sponsored by:

License

Licensed under MIT.

point-of-view's People

Contributors

alemagio avatar alex2844 avatar alynxzhou avatar amer8 avatar bigmurry avatar cemremengu avatar climba03003 avatar danielkhan avatar delvedor avatar dependabot-preview[bot] avatar dependabot[bot] avatar dtex avatar eomm avatar fdawgs avatar greenkeeper[bot] avatar gunjam avatar mcollina avatar mohd-akram avatar mroderick avatar mrowa96 avatar multivoltage avatar mweberxyz avatar ovhemert avatar rafaelgss avatar rickbrunstedt avatar robinvdvleuten avatar shmaxuti avatar smartiniongithub avatar ttpo100ajiex avatar uzlopak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

point-of-view's Issues

An in-range update of marko is breaking the build 🚨

Version 4.4.0 of marko just got published.

Branch Build failing 🚨
Dependency marko
Current Version 4.3.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As marko is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

allow setting content-type when calling `view(template, obj)`

hey there- I recently started playing around with Fastify, so excuse me if i just missed something before making this issue.

I have a use case where i want to output xml (rss feed). The rss template is actually in a pug template. This is just because it's easier to work with.
So the flow is-- I go get my data, set the content-type with reply.header('Content-Type', 'text/xml'); then call view() with the template and my data.

The expectation is that i'll end up with an xml response. What actually happens is that the content-type gets overridden when you call view() with a template-
https://github.com/fastify/point-of-view/blob/master/index.js#L53

I'm curious if there's a specific reason behind this? Or if it's acceptable to check for a content-type defined, and not assign text/html if there is one?

An in-range update of marko is breaking the build 🚨

The devDependency marko was updated from 4.14.22 to 4.14.23.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

marko is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 4 commits.

  • a5d80a4 4.14.23
  • 2a0ecec Update changelog
  • 6ed4e9d Improve optimization for nested tags wrapped in an if statement (#1249)
  • ecae71c Fix 'marko is using deprecated features' message (#1250)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of request is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 2.84.0 of request was just published.

Branch Build failing 🚨
Dependency request
Current Version 2.83.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

request is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 6 commits.

  • d77c839 Update changelog
  • 4b46a13 2.84.0
  • 0b807c6 Merge pull request #2793 from dvishniakov/2792-oauth_body_hash
  • cfd2307 Update hawk to 7.0.7 (#2880)
  • efeaf00 Fixed calculation of oauth_body_hash, issue #2792
  • 253c5e5 2.83.1

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Multiple Templates Directory (with Template Inheritance)

Is multiple templates directory like the one below supported? Since some of the template engines supported allows extension of templates (template inheritance) from other templates (e.g. nunjucks).

root
└───modules
│   │   └───home
│   │   │   │   index.js
│   │   │   └───templates
│   │   │   │   └───home
│   │   │   │   │   │   home-template1.html (inherits from base.html)
│   │   │   │   │   │   home-template2.html (inherits from base.html)
│   │   └───about
│   │   │   │   index.js
│   │   │   └───templates
│   │   │   │   └───about
│   │   │   │   │   │   home-template1.html (inherits from base.html)
│   │   │   │   │   │   home-template2.html (inherits from base.html)
└───templates
│   │   base.html

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 13.7.6 to 13.7.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Update nunjucks to latest release

Hi all,
I just see that a new release of Nunjucks is available, so could be good to use it.
See here.
And update other dependencies too, but keep Fastify to pre-1.0.x (0.43.0), ok ?

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 11.10.4 to 11.10.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of tap is breaking the build 🚨

The devDependency tap was updated from 12.4.0 to 12.4.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tap is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 7 commits.

  • c17e6db 12.4.1
  • 88eb85b Ignore timers in _getActiveHandles reporting
  • 58699d7 remove unused js-yaml from lib/tap.js
  • 4621be8 node 11 no longer blocks process.reallyExit
  • 74e4671 Add node 11 to travis
  • b074a1a Don't use bluebird
  • e8fb7df update nyc to v13

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Split test.js into multiple files

I think test.js is becoming very hard to maintain as there is a lot of duplicated code. I think we should split into multiple files and create some helpers to reduce code duplication as much as possible.

TypeError: reply.view is not a function

I separate and registe rendering config in other file.

// marko_conf.js
const path = require("path");
module.exports = async (fastify, opts) => {
	fastify.register(require("point-of-view"), {
		engine: {
			marko: require("marko"),
		},
		includeViewExtension: false,
		templates: path.join(__dirname, "./templates")
	});
};
// app.js
const fastify = require("fastify")();

fastify.register(require("./marko_conf.js"));
fastify.get("/", (req, reply) => {
	reply.view("index.marko", { text: "hi" });
});

fastify.listen(3000);

/home/jimmy/Desktop/test/app.js:7
	reply.view("index.marko", { text: "hi" });
	      ^
TypeError: reply.view is not a function
    at Object.fastify.get (/home/jimmy/Desktop/test/app.js:7:8)
    at preHandlerCallback (/home/jimmy/Desktop/test/node_modules/fastify/lib/handleRequest.js:88:30)
    at handler (/home/jimmy/Desktop/test/node_modules/fastify/lib/handleRequest.js:72:5)
    at handleRequest (/home/jimmy/Desktop/test/node_modules/fastify/lib/handleRequest.js:22:5)
    at onRunMiddlewares (/home/jimmy/Desktop/test/node_modules/fastify/fastify.js:346:5)
    at middlewareCallback (/home/jimmy/Desktop/test/node_modules/fastify/fastify.js:334:7)
    at Object.routeHandler [as handler] (/home/jimmy/Desktop/test/node_modules/fastify/fastify.js:224:7)
    at Router.lookup (/home/jimmy/Desktop/test/node_modules/find-my-way/index.js:265:17)
    at Server.emit (events.js:180:13)
    at parserOnIncoming (_http_server.js:642:12)

but, if I regist in the same file that will work

await fastify.view Cannot read property 'send' of undefined

Before you submit an issue we recommend you drop into the Gitter community or Fastify Help and ask any questions you have or mention any problems you've had getting started with Fastify.

Please read this entire template before posting any issue. If you ignore these instructions
and post an issue here that does not follow the instructions, your issue might be closed,
locked, and assigned the missing discussion label.

🐛 Bug Report

A clear and concise description of what the bug is.
image
this.header return undefined
so "message": "Cannot read property 'send' of undefined"

change to:
this.header('Content-Type', 'text/html; charset=' + charset)
this.send(html)

To Reproduce

Steps to reproduce the behavior:

Paste your code here:

this.header('Content-Type', 'text/html; charset=' + charset)
this.send(html)

Change dependency on request with simple-get

Hi all,
for consistency with Fastify (and with some other core plugins) I think could be useful to change the devDependency from 'request' to latest 'simple-get', and maybe update all other dependencies ...
What do you think ?
If accepted, I'll do a PR with changes (even related tests of course).

Thanks, Sandro

An in-range update of nunjucks is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 3.1.1 of nunjucks was just published.

Branch Build failing 🚨
Dependency nunjucks
Current Version 3.1.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

nunjucks is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 7 commits.

  • 6f3e4a3 v3.1.1
  • eed7b2d Fix bug that broke template caching. fixes #1074
  • db8e3c3 Fix error when running npm install nunjucks --no-bin-links
  • 2c97201 try/catch require of chokidar to make it truly optional
  • a65d3b8 bower forbids minified js in the main property
  • 2c98065 Add nunjucks folder to bower.json ignore
  • 470181d Prepare for next release

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Make data optional

Why is the data argument required? In my application I have several templates who don't need any variables for example.

Improve codebase

The actual options for getHeader is not compliant to the fastify codebase that support the chaining-call:

ex: this.header('Content-Type', 'text/html; charset=' + charset).send(html)

It would be awsome if @momofan or @florianb could work on this 💪

Mode info on how to implement this improvement:

point-of-view/index.js

Lines 52 to 53 in b7345f0

getHeader: () => {},
header: () => {},

They are replicating the core Reply methods and should behave accordingly. In fact, I'm not sure why the view decoration is on the server object. Views should be rendered in the context of a request, and in particular the context of sending a reply. So I would think the view decoration should be fastify.decorateReply('view', function () {}). Which would mean the following would be an outline of a solution:

fastify.decorateReply('view', function () {
  // other details omitted
  renderer.apply({getHeader, header}, args)

  function getHeader (key) {
    return this.getHeader(key)
  }

  function header (key, val) {
    return this.header(key, val)
  }
})

Originally posted by @jsumners in #129

Usage within async handler function?

Calling reply.view in an async handler function logs an error:

{"level":50,"time":1541536966444,"msg":"Promise may not be fulfilled with 'undefined' when statusCode is not 204","pid":17183,"hostname":"ip-10-10-10-218.ec2.internal","reqId":1,"err":{"type":"Error","message":"Promise may not be fulfilled with 'undefined' when statusCode is not 204","stack":"Error: Promise may not be fulfilled with 'undefined' when statusCode is not 204\n    at /home/steve/ff-pov/node_modules/fastify/lib/wrapThenable.js:18:34"},"v":1}

The rendered html will actually arrive at the browser, but the above message will be logged to console.

Here is example server:

const fastify = require("fastify")({
  logger: true
});

fastify.register(require("point-of-view"), {
  engine: {
    nunjucks: require("nunjucks")
  }
});

async function something() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(new Date());
    }, 1000);
  });
}

fastify.get("/", async (req, reply) => {
  const t = await something();
  reply.view("/home.html", { text: t });
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log(`server listening on ${fastify.server.address().port}`);
});

Is there a better way to do this?

Error with ejs-mate: cb is not a function

Getting the following error when rendering a view using the [email protected] engine:

{
  "level": 50,
  "time": 1545039516427,
  "msg": "cb is not a function",
  "pid": 5396,
  "hostname": "goliatorum.home",
  "reqId": 1,
  "req": {
    "id": 1,
    "method": "GET",
    "url": "/login",
    "hostname": "127.0.0.1:3003",
    "remoteAddress": "127.0.0.1",
    "remotePort": 53826
  },
  "res": { "statusCode": 500 },
  "err": {
    "type": "TypeError",
    "message": "cb is not a function",
    "stack": "TypeError: cb is not a function\n    at Function.compile (/src/node_modules/ejs-mate/lib/index.js:130:3)\n    at _readCallback (/src/node_modules/point-of-view/index.js:139:39)\n    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)"
  },
  "v": 1
}

This is due to ejs-mate expecting a callback in their compile function:

function compile(file, options, cb) 
  • point-of-view: 2.1.0

Can't include outside ejs file

hello, i tried to include my header and footer but it doesn't works
how can i include it in my file

Here's my declaration
screen shot 2018-12-23 at 14 25 55

here's my folder structure
screen shot 2018-12-23 at 14 25 28

i tried to import like this
<% include views/admin/header %>

and get error like this
{"statusCode":500,"error":"Internal Server Error","message":"Could not find the include file "views/admin/header""}

An in-range update of fastify is breaking the build 🚨

The devDependency fastify was updated from 2.12.0 to 2.12.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

fastify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v2.12.1

📚 PR:

  • Added fastify-esso plugin (#2084)
  • add comma to queryStringJsonSchema (#2085)
  • Throws error if an invalid status code is sent (#2082)
  • chore: greenkeeper ignore semver (#2095)
  • Fix inaccurate type of setErrorHandler (#2092)
  • Fixed typo res.res to reply.res (#2099)
  • docs: use computed key when assigning property to request (#2100)
  • types: add type of this to the not found handler (#2102)
  • docs: fix header and body generic types (#2103)
  • fix: multiple route same schema (#2108)
  • http2: fix req.hostname not set (#2113)
  • Added fastify-axios plugin (#2118)
  • docs: Clarify reply.redirect status code docs (#2121)
Commits

The new version differs by 14 commits.

  • c4a83ae Bumped v2.12.1
  • 350f00b docs: Clarify reply.redirect status code docs (#2121)
  • a378dd5 Added fastify-axios plugin (#2118)
  • 093947b http2: fix req.hostname not set (#2113)
  • 6f79a90 fix: multiple route same schema (#2108)
  • 98ca7fd docs: fix header and body generic types (#2103)
  • 772cf5e types: add type of this to the not found handler (#2102)
  • b44d859 docs: use computed key when assigning property to request (#2100)
  • da4c89d Fixed typo res.res to reply.res (#2099)
  • 743ad74 Fix inaccurate type of setErrorHandler (#2092)
  • f971751 chore: greenkeeper ignore semver (#2095)
  • 41cd02f Throws error if an invalid status code is sent (#2082)
  • 14b4e02 add comma to queryStringJsonSchema (#2085)
  • 1c52b9f Added fastify-esso plugin (#2084)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Include issue

Hi guys,

Have any of you got troubles with including other EJS components within an EJS file? I'm getting following error "Error: Could not find include include file.".

Example:
<% include header %> within the "index.ejs" file.

It works in Express, so maybe I just can't find the relative path somehow. All my ejs files is located in the same folder, so shouldn't be an issue.

Thanks.

Use handlebars with default main layout

I recently migrated my app from express to fastlify. It's awesome what it did performance wise 👍

I'm using Handlebars as my view engine, using a layouts/main.hbs which has all the boilerplate code. (Head, Loading Spinner, etc.)
But how can I configure point-of-view to use the main layout by default?
I tried it using all options with no success...

Promise not fulfilled when using res.view

Hello,

I just want to render a page with variables. Passing getting the variables and passing them with res.send works fine but if I use res.view I get an error that the promise is not fulfilled. I am pretty new to Javascript and especially to async functions.

My code looks as follow:

exports.show = async (req, res) => {
	try {
		const [var1, var2] = await Promise.all([
			getUser(id),
			getInfo(id)
		])
		res.view("index.pug", {var1: var1, var2: var2})
	} catch {
		if (err) throw err
	}
}

What am I doing wrong?
Thanks

Make the data-parameter of `.view(page, data)` for all template-engines optional.

Before you submit an issue we recommend you drop into the Gitter community or Fastify Help and ask any questions you have or mention any problems you've had getting started with Fastify.

Please read this entire template before posting any issue. If you ignore these instructions
and post an issue here that does not follow the instructions, your issue might be closed,
locked, and assigned the missing discussion label.

🚀 Feature Proposal

Make the data-parameter of .view(page, data) for all template-engines optional.

I already created the corresponding PR #131.

This seems to catch up to the PR #52.

Motivation

I use the view-function often with implicitly provided data via the defaultContext. Currently this efforts in any case (than the pure ejs-template-handler) that an empty objeckt ({}) must be provided.

Since the pure ejs-view-function treats the data-parameter already as optional, i expected it to be optional for the other template-engines, too.

Example

Current syntax

  fastify.register(require('../index'), {
    engine: {
      'ejs-mate': require('ejs-mate')
    },
    defaultContext: { text: 'text' },
    templates: 'templates'
  })

  fastify.get('/', (req, reply) => {
    reply.view('index.ejs', {})
  })

Future syntax

  fastify.register(require('../index'), {
    engine: {
      'ejs-mate': require('ejs-mate')
    },
    defaultContext: { text: 'text' },
    templates: 'templates'
  })

  fastify.get('/', (req, reply) => {
    reply.view('index.ejs')
  })

default encoding in views

Hi all,
I just see that if I don't set in explicit way reply encoding, Firefox will complaint on missing encoding.
So for reply.view I need to do (anytime) something like:
reply.type('text/html; charset=utf-8').view('index', data)

What do you think on adding that encoding as default for views (could be a good default) ?
Or check the encoding of related view (file) ... but this could be too much and alittle more expensive in performances.

What do you think ?

Thanks,
Sandro

How do I get partials working with Handlebars?

I'm working on transitioning an Express app to Fastify. Here's my server code:

const fastify = require("fastify")();
const handlebars = require("handlebars");
const log = console.log; // eslint-disable-line

fastify.register(require("point-of-view"), {
  engine: {
    handlebars: handlebars
  },
  templates: `${__dirname}/views`
});

fastify.get("/", async (request, reply) => {
  reply.view("/home.html", { body: `<p>Cool</p>` });
});

const start = async () => {
  try {
    await fastify.listen(process.env.PORT || 8080, process.env.IP || "0.0.0.0");
  } catch (err) {
    fastify.log.error(err);
    process.exit(1);
  }

  log(`Server listening on ${fastify.server.address().port}`);
}

start();

This is in my home.html template:

<!DOCTYPE html>
<html lang="en">
  {{> views/head }}

  <body class="home">
    {{> views/navigation }}

    <main>
      {{{ body }}}
    </main>

    {{> views/footer }}
  </body>
</html>

The error message I get is "The partial views/head could not be found". The thing is though, views/head.html exists. Nothing I have tried is working.

An in-range update of fastify is breaking the build 🚨

Version 1.11.0 of fastify was just published.

Branch Build failing 🚨
Dependency fastify
Current Version 1.10.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

fastify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes v1.11.0

Features

  • Added pluginTimeout option - #1088

Internals

  • Override address in listen instead of listenPromise - #1102
  • Rename and call unknown method tests from http2 - #1095
  • Ensure that error-in-post test is run - #1096
  • Add test for trust proxy with function - #1098

Documentation

  • Move Server-Methods into Factory - #1101
  • Update Validation-and-Serialization.md - #1094
Commits

The new version differs by 11 commits.

  • c62ace8 Bumped v1.11.0
  • acf3950 Override address in listen instead of listenPromise (#1102)
  • e6bca66 Move Server-Methods into Factory (#1101)
  • ba9a629 Update Validation-and-Serialization.md (#1094)
  • e77cae9 Add test for trust proxy with function (#1098)
  • 6bce249 Ensure that error-in-post test is run (#1096)
  • 3895a75 Rename and call unknown method tests from http2 (#1095)
  • 1f750e6 Ignore pino in greenkeeper, it's a semver-major change
  • 28436d1 chore(package): update concurrently to version 4.0.0 (#1091)
  • a258482 Update TypeScript to 3.0.1 (#1092)
  • 50bcf6b Added pluginTimeout option. (#1088)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

$var is not defined

Master

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title><%= title ? title : '' %> - Backbeard</title>
  </head>
  <body>
    <% include ../inc/navbar %>
    <div class="container">
      <%- body -%>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>

Index

<% layout('layouts/master') -%>
<h1>I am the template</h1>

Route

fastify.get('/', async (request, reply) => {
    return await fastify.view('/index.ejs', { title: 'text' })
})

I also tried options like reply.view with and without async. I tried everything. I do not know what I do wrong

An in-range update of nunjucks is breaking the build 🚨

The devDependency nunjucks was updated from 3.1.3 to 3.1.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nunjucks is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 7 commits.

  • 11262e5 Release v3.1.4
  • bcd45fc Merge pull request #1165 from stigkj/master
  • 40480f0 Fix engine version for Node v11.1.0
  • 3512ca6 Merge pull request #1161 from jonathanchu/master
  • 9dc07dc Fix dependency version for node v11.0.0
  • 39bb716 Merge pull request #1126 from TheDancingCode/issue-126
  • 4d4dc40 Escape unicode newlines when compiling

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

error when using layouts in pug

App.register(require('point-of-view'), { engine: { pug: require('pug') }, options:{}, templates: 'templates' })

I got :
Error: the "filename" option is required to use includes and extends with "relative" paths
in the file :

extends ./layout.pug block content p hola

How I pass filename to options object inside the configuration ?

An in-range update of marko is breaking the build 🚨

Version 4.12.0 of marko was just published.

Branch Build failing 🚨
Dependency marko
Current Version 4.11.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

marko is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 8 commits.

  • b5f5f66 update changelog
  • c6829e1 4.12.0
  • 8bcb848 enable style arrays (#1082)
  • 280f734 fixes #1075 - cannot compile dynamic tag at root with user key (#1081)
  • f48e22c Fixes #1078 - don't mutate spread attributes (#1080)
  • f5ebda8 Tag params (#1076)
  • 63b0aeb dynamic tag fixes
  • 2ec6695 update changelog

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of marko is breaking the build 🚨

The devDependency marko was updated from 4.14.5 to 4.14.6.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

marko is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 4 commits.

  • 00ae73e 4.14.6
  • e8e4a41 Update changelog, remove old roadmap
  • 3f1d742 Remove deprecations already moved to the migrate stage (#1196)
  • 0fdc5a2 Whitelist files published to npm (#1197)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Refactoring to support async/await

I think it's due that we improve the support for async/await in this module.

Currently, it's not working as expected mainly because loading templates could be asynchronous, and that does not work well with the internal call to .send(), as there is no way to await that.

It following should work with any template engine.

What we need as next steps is a proposal to implement an API that could be awaited upon, and then an implementation.

how to render a view inside a promise on routing

i can only return json if i'm calling a promise inside the router, how do i do something like this?

i am creating amp pages so i cannot consume api from frontend, i'm using point-of-view to render the data on the layout.

fastify.get('*', function (req, res) {
    return new Promise(function (resolve) {
      axios.get(`/contents`).then(({data}) => {
        // res.view('blog/content', {
        //   data: data
        // });
        resolve() //what to resolve here?
      }, err => {
        res.code(404)
        resolve(res) //
      })
    })
  });

Update for Fastify 2.0

Error: fastify-plugin - expected '^1.1.0' fastify version, '2.0.0' is installed

If/when someone have time,

😄 🐭 🧀

An in-range update of fastify is breaking the build 🚨

Version 1.11.2 of fastify was just published.

Branch Build failing 🚨
Dependency fastify
Current Version 1.11.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

fastify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v1.11.2

Internals

  • Handle promises in the error handler with the same logic of normal handlers - #1134
  • Rename ContentTypeParser - #1123
  • after should not cause inject() to be called - #1132

Documentation

  • Add trivikr@ to the collaborators list - #1139
  • Updated ecosystem doc - #1137
Commits

The new version differs by 13 commits.

  • 4e047a8 Bumped v1.11.2
  • c40ea62 Add trivikr@ to the collaborators list (#1139)
  • 0a27c92 Correct typos in Github Issue Template (#1140)
  • 5b18645 Updated ecosystem doc (#1137)
  • 0a874b9 Handle promises in the error handler with the same logic of normal handlers (#1134)
  • cce1a85 Rename ContentTypeParser (#1123)
  • 6d302a5 Add test for error fixed in mcollina/avvio#74 (#1132)
  • 60b85e7 Update Validation-and-Serialization.md (#1124)
  • d6982ea Remove/Merge redundant decorate functions (#1120)
  • baeebef Updated standard to v12. (#1121)
  • 7c8401d Update ContentTypeParser.js (#1122)
  • a14397d ecosystem in alphabetical order
  • 8a0c618 Update Ecosystem.md (#1125)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of nunjucks is breaking the build 🚨

The devDependency nunjucks was updated from 3.1.7 to 3.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nunjucks is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v3.2.0
Commits

The new version differs by 11 commits.

  • ff5571c Release v3.2.0
  • f997a52 Add NodeResolveLoader
  • 34b0a26 Fix syntax typos in CONTRIBUTING.md
  • 55e0b7a Set dash as joiner element
  • c99154e Update faq.md
  • 1338712 Emit 'load' events on Loader and Environment instances
  • 057e7b3 Add test for line/column info in user-function exception
  • bcf38f3 Emit line and column info for functions
  • fbddcd5 lexer more accurately tracks token line and column information
  • 889ef80 Add nodejs versions 10 and 11 to CI, remove 6 and 9
  • b828158 Fix documentation typo

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.