github-view.js
This file
Path
examples/view-constructor/github-view.js
53 lines · 1.0 KiB · JavaScript
Last changed by
fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
History of this fileTake it
The walk stopped after 200 commits: lines older than 2a0c35a point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 1–2why, one step back1'use strict'2Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 3–6why, one step back3/**4 * Module dependencies.5 */6fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 7–8why, one step back7var https = require('node:https');8var path = require('node:path');Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 9–53why, one step back9var extname = path.extname;1011/**12 * Expose `GithubView`.13 */1415module.exports = GithubView;1617/**18 * Custom view that fetches and renders19 * remove github templates. You could20 * render templates from a database etc.21 */2223function GithubView(name, options){24 this.name = name;25 options = options || {};26 this.engine = options.engines[extname(name)];27 // "root" is the app.set('views') setting, however28 // in your own implementation you could ignore this29 this.path = '/' + options.root + '/master/' + name;30}3132/**33 * Render the view.34 */3536GithubView.prototype.render = function(options, fn){37 var self = this;38 var opts = {39 host: 'raw.githubusercontent.com',40 port: 443,41 path: this.path,42 method: 'GET'43 };4445 https.request(opts, function(res) {46 var buf = '';47 res.setEncoding('utf8');48 res.on('data', function(str){ buf += str });49 res.on('end', function(){50 self.engine(buf, options, fn);51 });52 }).end();53};