Comparing version 0.5.4 to 0.5.5
@@ -10,2 +10,3 @@ /// <reference types="node" /> | ||
export * from './router/modules'; | ||
export * from './types'; | ||
export declare function createApp(structure: TBranchData): RequestListener; |
@@ -45,2 +45,3 @@ "use strict"; | ||
__exportStar(require("./router/modules"), exports); | ||
__exportStar(require("./types"), exports); | ||
function createApp(structure) { | ||
@@ -47,0 +48,0 @@ const router = (0, create_router_1.default)(structure); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ex_1 = __importDefault(require("../built-in/tools/ex")); | ||
function createCookies(req, res) { | ||
const result = {}; | ||
const values = {}; | ||
const values = parseCookieHeader(req.headers.cookie); | ||
function get(key) { | ||
var _a, _b; | ||
if (Object.prototype.hasOwnProperty.call(values, key)) | ||
return values[key]; | ||
const cookies = (_b = (_a = req.headers.cookie) === null || _a === void 0 ? void 0 : _a.split('; ')) !== null && _b !== void 0 ? _b : []; | ||
const cookie = cookies.find(cookie => cookie.startsWith(`${key}=`)); | ||
if (!cookie) | ||
return undefined; | ||
return cookie.slice(cookie.indexOf('=') + 1); | ||
return values[key]; | ||
} | ||
function set(key, value, options) { | ||
const attrs = [`${key}=${value}`]; | ||
validateCookieName(key); | ||
const attrs = [`${key}=${encodeURIComponent(value)}`]; | ||
if (options) { | ||
@@ -42,3 +40,3 @@ if (options.expires !== undefined) | ||
set(key, '', { maxAge: 0 }); | ||
values[key] = undefined; | ||
delete values[key]; | ||
} | ||
@@ -48,2 +46,20 @@ return { get, set, remove }; | ||
exports.default = createCookies; | ||
function parseCookieHeader(cookie = '') { | ||
const result = {}; | ||
for (const part of cookie.split('; ')) { | ||
const [key, value] = part.split('='); | ||
result[key] = decodeURIComponent(value !== null && value !== void 0 ? value : ''); | ||
} | ||
return result; | ||
} | ||
function validateCookieName(name) { | ||
if (name.includes(';')) | ||
throw ex_1.default.InternalServerError(`Cookie name "${name}" contains invalid character ";"`); | ||
if (name.includes('=')) | ||
throw ex_1.default.InternalServerError(`Cookie name "${name}" contains invalid character "="`); | ||
if (name.includes(',')) | ||
throw ex_1.default.InternalServerError(`Cookie name "${name}" contains invalid character ","`); | ||
if (name.includes(' ')) | ||
throw ex_1.default.InternalServerError(`Cookie name "${name}" contains invalid character " "`); | ||
} | ||
function formatExpires(expires) { | ||
@@ -50,0 +66,0 @@ if (expires instanceof Date) |
@@ -7,3 +7,3 @@ "use strict"; | ||
const create_regexp_1 = __importDefault(require("./create-regexp")); | ||
const main_1 = require("../main"); | ||
const ex_1 = __importDefault(require("../built-in/tools/ex")); | ||
const logger_1 = __importDefault(require("../util/logger")); | ||
@@ -44,3 +44,3 @@ const validate_1 = require("../util/validate"); | ||
}; | ||
return Object.assign(Object.assign({}, branch), { method, handles: [...branch.handles, () => { throw main_1.Ex.NotFound(); }] }); | ||
return Object.assign(Object.assign({}, branch), { method, handles: [...branch.handles, () => { throw ex_1.default.NotFound(); }] }); | ||
} | ||
@@ -47,0 +47,0 @@ function getMethods(routes, autoHead) { |
{ | ||
"name": "kequapp", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "Non-intrusive Node JavaScript web app framework", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -9,6 +9,4 @@ <img alt="kequapp" src="https://github.com/Kequc/kequapp/blob/0.2-wip/logo.png?raw=true" width="142" height="85" /> | ||
Does the best it can to stay out of the way and leverage Node's built in features. Comes with a great deal of conveniences which makes it easy to structure an application with regard to modularity, body parsing, cookies, and testing. | ||
Does the best it can to stay out of the way and leverage Node's built in features. Comes with a great deal of little stuff which makes it easy to structure an application with regard to modularity, CORS, body parsing, cookies, and testing without dependencies. | ||
Intended to be simple, powerful, and allows us to intercede at any time. | ||
**Features** | ||
@@ -54,3 +52,3 @@ | ||
This example responds to all `'GET'`, and `'HEAD'` requests made to `'/'` otherwise a `404 Not Found` error will be thrown. The framework comes with a built-in error handler and some renderers. We will look at how to create our own, but for now we don't need to worry about it. | ||
This example responds to all `'GET'`, and `'HEAD'` requests made to `'/'` otherwise a `404 Not Found` error will be thrown. The framework comes with a built-in error handler and some renderers so for now this is all we need. | ||
@@ -389,6 +387,2 @@ # # createApp() | ||
#### **`logger`** | ||
The logger being used by the application. | ||
#### **`cookies`** | ||
@@ -409,2 +403,6 @@ | ||
#### **`logger`** | ||
The logger being used by the application. | ||
#### **`getBody`** | ||
@@ -411,0 +409,0 @@ |
118454
2232
872