Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/view

Package Overview
Dependencies
Maintainers
17
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/view - npm Package Compare versions

Comparing version 7.1.0 to 7.1.1

examples/example-async.js

28

index.js

@@ -170,3 +170,3 @@ 'use strict'

function getRequestedPath (fastify) {
return (fastify && fastify.request) ? fastify.request.context.config.url : null
return (fastify && fastify.request) ? fastify.request.routerPath : null
}

@@ -658,8 +658,3 @@ // Gets template as string (or precompiled for Handlebars)

data = Object.assign({}, defaultCtx, this.locals, data)
// Append view extension (Eta will append '.eta' by default,
// but this also allows custom extensions)
page = getPage(page, 'eta')
engine.renderFile(page, data, config, (err, html) => {
if (err) return this.send(err)
const sendContent = html => {
if (

@@ -677,3 +672,20 @@ config.useHtmlMinifier &&

this.send(html)
})
}
data = Object.assign({}, defaultCtx, this.locals, data)
// Append view extension (Eta will append '.eta' by default,
// but this also allows custom extensions)
page = getPage(page, 'eta')
if (opts?.async ?? globalOptions.async) {
engine
.renderFile(page, data, config)
.then(sendContent)
.catch(err => this.send(err))
} else {
engine.renderFile(page, data, config, (err, html) => {
err
? this.send(err)
: sendContent(html)
})
}
}

@@ -680,0 +692,0 @@

{
"name": "@fastify/view",
"version": "7.1.0",
"version": "7.1.1",
"description": "Template plugin for Fastify",
"main": "index.js",
"types": "types/index.d.ts",
"scripts": {
"example": "node example.js",
"example-with-options": "node example-ejs-with-some-options.js",
"example-typescript": "npx ts-node test/index.test-d.ts",
"example": "node examples/example.js",
"example-with-options": "node examples/example-ejs-with-some-options.js",
"example-typescript": "npx ts-node types/index.test-d.ts",
"lint": "standard",
"test-with-snapshot": "cross-env TAP_SNAPSHOT=1 tap test/test-ejs-with-snapshot.js",
"test": "standard && tap -J test/*.js && tsd"
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:typescript": "tsd"
},

@@ -52,3 +56,2 @@ "repository": {

"html-minifier": "^4.0.0",
"html-minify-stream": "^2.0.0",
"liquidjs": "^9.15.1",

@@ -64,9 +67,9 @@ "mustache": "^4.0.1",

"tap": "^16.0.0",
"tsd": "^0.22.0",
"twig": "^1.13.3",
"typescript": "^4.0.2"
"tsd": "^0.24.1",
"twig": "^1.13.3"
},
"tsd": {
"directory": "test"
},
"pre-commit": [
"lint",
"test"
],
"publishConfig": {

@@ -73,0 +76,0 @@ "access": "public"

@@ -104,2 +104,3 @@ # @fastify/view

- `defaultContext`: The template variables defined here will be available to all views. Variables provided on render have precendence and will **override** this if they have the same name. Default: `{}`. Example: `{ siteName: "MyAwesomeSite" }`.
- `maxCache`: In `production` mode, maximum number of templates file and functions caches. Default: `100`. Example: `{ maxCache: 100 }`.

@@ -221,23 +222,2 @@ Example:

To utilize [`html-minify-stream`](https://www.npmjs.com/package/html-minify-stream) in the rendering process with template engines that support streams,
you can add the option `useHtmlMinifyStream` with a reference to `html-minify-stream`, and the optional `htmlMinifierOptions` option is used to specify the options just like `html-minifier`:
```js
// get a reference to html-minify-stream
const htmlMinifyStream = require('html-minify-stream')
// optionally defined the html-minifier options that are used by html-minify-stream
const minifierOpts = {
removeComments: true,
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true
}
// in template engine options configure the use of html-minify-stream
options: {
useHtmlMinifyStream: htmlMinifyStream,
htmlMinifierOptions: minifierOpts
}
```
To filter some paths from minification, you can add the option `pathsToExcludeHtmlMinifier` with list of paths

@@ -244,0 +224,0 @@ ```js

@@ -989,1 +989,32 @@ 'use strict'

})
test('fastify.view with eta engine and async in production mode', t => {
t.plan(3)
const fastify = Fastify()
const data = { text: 'text' }
fastify.register(pointOfView, {
engine: {
eta
},
production: true,
options: {
async: true
}
})
fastify.ready(err => {
t.error(err)
fastify.view('templates/index.eta', data).then((compiled) => {
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)
fastify.view('templates/index.eta', null)
.then(() => { t.fail('should not be here') })
.catch((err) => {
t.ok(err instanceof Error)
fastify.close()
})
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc