Git Product home page Git Product logo

point-of-view's Issues

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

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 🌴

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.

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...

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 🌴

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.

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')
  })

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 🌴

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 🌴

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)

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 🌴

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 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 🌴

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

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

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 🌴

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.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 🌴

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""}

Make data optional

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

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 🚨

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 🌴

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 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 🌴

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 🌴

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 🌴

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.

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) //
      })
    })
  });

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

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?

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

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 🌴

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 🌴

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.

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

$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

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

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 🌴

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.