From 153b865e791279068466b8c9a04090fbffbc61b5 Mon Sep 17 00:00:00 2001 From: Nick Baugh Date: Tue, 12 Sep 2017 05:52:27 -0400 Subject: [PATCH] Added cache-pug-templates --- README.md | 4 ++-- template/package.json | 1 + template/web.js | 14 +++++++++++--- template/yarn.lock | 10 +++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9fde553c..16bbf582 100644 --- a/README.md +++ b/README.md @@ -426,7 +426,7 @@ DEBUG=* yarn start 4. See the [Continuous Integration and Code Coverage](#continuous-integration-and-code-coverage) and [Tutorials](#tutorials) sections below for instructions on how to setup continuous integration, code coverage, and deployment. -5. If you specify the environment variables `AWS_CF_DOMAIN` then your assets will need to be published to Amazon S3/Cloudfront. To do so run `npm run publish-assets` (or with yarn as `yarn publish-assets`). +5. If you specify the environment variables `AWS_CF_DOMAIN` then your assets will need to be published to Amazon S3/Cloudfront. To do so run `npm run publish-assets` (or with yarn as `yarn publish-assets`). #### Tests @@ -641,7 +641,7 @@ If you are seeking permission to use these trademarks, then please [contact us]( [MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com) -## +## # diff --git a/template/package.json b/template/package.json index cf68e9d3..c77729af 100644 --- a/template/package.json +++ b/template/package.json @@ -23,6 +23,7 @@ "boom": "^5.2.0", "bootstrap": "^4.0.0-beta", "bootstrap-social": "^5.1.1", + "cache-pug-templates": "^0.0.4", "chalk": "^2.1.0", "chart.js": "^2.6.0", "clipboard": "^1.7.1", diff --git a/template/web.js b/template/web.js index 442d8a94..40efa47d 100644 --- a/template/web.js +++ b/template/web.js @@ -28,6 +28,7 @@ const flash = require('koa-better-flash'); const CSRF = require('koa-csrf'); const StoreIPAddress = require('@ladjs/store-ip-address'); const isajax = require('koa-isajax'); +const cachePugTemplates = require('cache-pug-templates'); // const Meta = require('koa-meta'); const Timeout = require('koa-better-timeout'); const Mongoose = require('@ladjs/mongoose'); @@ -68,6 +69,9 @@ let server; app.on('error', helpers.logger.contextError.bind(helpers.logger)); app.on('log', helpers.logger.log.bind(helpers.logger)); +// inherit cache variable for cache-pug-templates +app.cache = config.views.locals.cache; + // trust proxy app.proxy = true; @@ -223,9 +227,13 @@ if (config.protocols.web === 'http') server = http.createServer(app.callback()); else server = https.createServer(config.ssl.web, app.callback()); if (!module.parent) - server = server.listen(config.ports.web, () => - helpers.logger.info(`web server listening on ${config.ports.web}`) - ); + server = server.listen(config.ports.web, () => { + helpers.logger.info(`web server listening on ${config.ports.web}`); + cachePugTemplates(app, redisClient, config.views.root, (err, cached) => { + if (err) return helpers.logger.error(err); + helpers.logger.debug(`successfully cached ${cached.length} views`); + }); + }); // handle process events and graceful restart const graceful = new Graceful({ diff --git a/template/yarn.lock b/template/yarn.lock index 235abe10..d869f4d7 100644 --- a/template/yarn.lock +++ b/template/yarn.lock @@ -464,7 +464,7 @@ async@^1.4.0, async@~1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" -async@^2.1.2: +async@^2.1.2, async@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d" dependencies: @@ -1549,6 +1549,14 @@ bytes@^2.3.0, bytes@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-2.5.0.tgz#4c9423ea2d252c270c41b2bdefeff9bb6b62c06a" +cache-pug-templates@^0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/cache-pug-templates/-/cache-pug-templates-0.0.4.tgz#49f4f4c918a9e3801c46a8042afe87bf817356df" + dependencies: + async "^2.5.0" + debug "^3.0.1" + rev-hash "^2.0.0" + cached-path-relative@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/cached-path-relative/-/cached-path-relative-1.0.1.tgz#d09c4b52800aa4c078e2dd81a869aac90d2e54e7"