Skip to content

Commit

Permalink
Updating dependencies, initial refactoring to new woodland
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Sep 3, 2019
1 parent afee006 commit 3580d96
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4,463 deletions.
4 changes: 2 additions & 2 deletions lib/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ renderers.set("text/html", (arg, req, headers, tpl = "") => {
return tpl.length > 0 ? tpl.replace(/\{\{title\}\}/g, req.server.config.title)
.replace("{{url}}", req.parsed.href.replace(req.parsed.protocol, protocol))
.replace("{{headers}}", Object.keys(headers).sort().map(i => `<tr><td>${i}</td><td>${sanitize(headers[i])}</td></tr>`).join("\n"))
.replace("{{formats}}", `<option value=''></option>${(Array.from(renderers.keys()).filter(i => i.indexOf("html") === -1).map(i => `<option value='${i.trim()}'>${i.replace(/^.*\//, "").toUpperCase()}</option>`).join("\n"))}`)
.replace("{{formats}}", `<option value=''></option>${Array.from(renderers.keys()).filter(i => i.indexOf("html") === -1).map(i => `<option value='${i.trim()}'>${i.replace(/^.*\//, "").toUpperCase()}</option>`).join("\n")}`)
.replace("{{body}}", sanitize(JSON.stringify(arg, null, 2)))
.replace("{{year}}", new Date().getFullYear())
.replace("{{version}}", req.server.config.version)
Expand All @@ -70,7 +70,7 @@ renderers.set("application/javascript", (arg, req, headers) => {
req.headers.accept = "application/javascript";
headers["content-type"] = "application/javascript";

return `${(req.parsed.searchParams.get("callback") || "callback")}(${JSON.stringify(arg, null, 0)});`;
return `${req.parsed.searchParams.get("callback") || "callback"}(${JSON.stringify(arg, null, 0)});`;
});

renderers.set("application/json", (arg, req) => JSON.stringify(arg, null, indent(req, req.server.config.json || 0)));
Expand Down
8 changes: 4 additions & 4 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Tenso extends Base {
.replace("%h", req.ip || "-")
.replace("%l", "-")
.replace("%u", req.parsed.username || "-")
.replace("%t", `[${(moment().format(this.config.logging.time))}]`)
.replace("%t", `[${moment().format(this.config.logging.time)}]`)
.replace("%r", `${req.method} ${req.parsed.pathname}${req.parsed.search} HTTP/${this.config.httpVersion}`)
.replace("%>s", res.statusCode)
.replace("%b", headers["content-length"] || "-")
Expand Down Expand Up @@ -295,7 +295,7 @@ class Tenso extends Base {

if (req.protect && (headers["cache-control"] || "").includes("private") === false) {
headers["cache-control"] = (headers["cache-control"] || res.getHeader("cache-control") || "").replace(/(private|public)(,\s)?/g, "");
headers["cache-control"] = `private${(headers["cache-control"].length > 0 ? ", " : "")}${(headers["cache-control"] || "")}`;
headers["cache-control"] = `private${headers["cache-control"].length > 0 ? ", " : ""}${headers["cache-control"] || ""}`;
}

if (canModify(req.method) === false && canModify(req.allow) && this.config.security.csrf === true && res.locals[this.config.security.key] !== void 0) {
Expand Down Expand Up @@ -484,7 +484,7 @@ class Tenso extends Base {
return this;
}

async send (req, res, body = "", status = 200, headers = {}) {
send (req, res, body = "", status = 200, headers = {}) {
let result, timer;

if (this.dtrace) {
Expand All @@ -496,7 +496,7 @@ class Tenso extends Base {

if (status !== 204 && status !== 304) {
if (body === null || typeof body.on !== "function") {
result = this.render(req, res, await this.final(req, res, hypermedia(this, req, serialize(req, body, status, headers), headers)), headers);
result = this.render(req, res, this.final(req, res, hypermedia(this, req, serialize(req, body, status, headers), headers)), headers);
headers["content-length"] = Buffer.byteLength(result);

if (req.method === "HEAD") {
Expand Down
17 changes: 10 additions & 7 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require("path"),
{URL} = require("url"),
retsu = require("retsu"),
keysort = require("keysort"),
redis = require("redis"),
session = require("express-session"),
cookie = require("cookie-parser"),
lusca = require("lusca"),
Expand Down Expand Up @@ -53,7 +54,7 @@ function delay (fn, n) {

function auth (obj, config) {
const ssl = config.ssl.cert && config.ssl.key,
realm = `http${(ssl ? "s" : "")}://${config.host}${(config.port !== 80 && config.port !== 443 ? ":" + config.port : "")}`,
realm = `http${ssl ? "s" : ""}://${config.host}${config.port !== 80 && config.port !== 443 ? ":" + config.port : ""}`,
async = config.auth.oauth2.enabled || config.auth.saml.enabled,
stateless = config.rate.enabled === false && config.security.csrf === false && config.auth.local.enabled === false,
authMap = {},
Expand All @@ -78,7 +79,7 @@ function auth (obj, config) {
obj.router.blacklist(middleware.asyncFlag);

each(groups, k => {
config.auth[k] = (config.auth[k] || []).map(i => new RegExp(`^${(i !== config.auth.uri.login ? i.replace(/\.\*/g, "*").replace(/\*/g, ".*") : "")}(\/|$)`, "i"));
config.auth[k] = (config.auth[k] || []).map(i => new RegExp(`^${i !== config.auth.uri.login ? i.replace(/\.\*/g, "*").replace(/\*/g, ".*") : ""}(\/|$)`, "i"));
});

each(Object.keys(config.auth), i => {
Expand All @@ -103,7 +104,8 @@ function auth (obj, config) {
sesh = Object.assign({secret: uuid()}, configSession);

if (config.session.store === "redis") {
sesh.store = new RedisStore(config.session.redis);
const client = redis.createClient(clone(config.session.redis));
sesh.store = new RedisStore({client});
}

fnCookie = cookie();
Expand Down Expand Up @@ -423,10 +425,11 @@ function bootstrap (obj) {
});

// Setting up router
obj.router.onconnect = obj.connect.bind(obj);
obj.router.onerror = obj.error;
obj.router.onfinish = obj.finish.bind(obj);
obj.router.onsend = obj.send.bind(obj);
obj.router.on("connect", obj.connect.bind(obj));
obj.router.off("error", obj.router.error);
obj.router.on("error", obj.error.bind(obj));
obj.router.on("finish", obj.finish.bind(obj));
obj.router.on("send", obj.send.bind(obj));

// Creating Etag manager
if (obj.config.etags.enabled) {
Expand Down
Loading

0 comments on commit 3580d96

Please sign in to comment.