/
githubmirror
/
express
Обзор
Документация
Войти
/
githubmirror
/
express
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/view-constructor/github-view.js
53 строки
1 KB
Szymon Łągiewka
fix(refactor): prefix built-in node module imports
10 янв 2025, 20:53
10 янв 2025, 20:53
4111359
Код
Авторство
О чём код?
'use strict' /** * Module dependencies. */ var https = require('node:https'); var path = require('node:path'); var extname = path.extname; /** * Expose `GithubView`. */ module.exports = GithubView; /** * Custom view that fetches and renders * remove github templates. You could * render templates from a database etc. */ function GithubView(name, options){ this.name = name; options = options || {}; this.engine = options.engines[extname(name)]; // "root" is the app.set('views') setting, however // in your own implementation you could ignore this this.path = '/' + options.root + '/master/' + name; } /** * Render the view. */ GithubView.prototype.render = function(options, fn){ var self = this; var opts = { host: 'raw.githubusercontent.com', port: 443, path: this.path, method: 'GET' }; https.request(opts, function(res) { var buf = ''; res.setEncoding('utf8'); res.on('data', function(str){ buf += str }); res.on('end', function(){ self.engine(buf, options, fn); }); }).end(); };