diff --git a/README.md b/README.md index 40f5268..f7d1232 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Roads is a simple web framework. It's similar to Express.js, but has some very i - [Parsing request bodies](#parsing-request-bodies) - [Parse Body Context](#parse-body-context) - [Remove trailing slash](#remove-trailing-slash) - - [Basic router](#basic-router) + - [Router](#router) - [applyMiddleware(road: *Road*)](#applymiddlewareroad-road) - [addRoute(method: *string*, path: *string*, fn: *function*)](#addroutemethod-string-path-string-fn-function) - [addRouteFile(filePath: *string*, prefix?: *string*)](#addroutefilefilepath-string-prefix-string) @@ -547,8 +547,8 @@ var road = new Road(); road.use(RemoveTrailingSlashMiddleware.middleware); ``` -## Basic router -This is a basic router middleware for roads. It allows you to easily attach functionality to HTTP methods and paths. +## Router +This is a Router middleware for roads. It allows you to easily attach functionality to HTTP methods and paths. Here's how you use it. diff --git a/example/ts/.gitignore b/example/ts/.gitignore index 3b8bd73..bba27cf 100644 --- a/example/ts/.gitignore +++ b/example/ts/.gitignore @@ -1 +1,2 @@ -public/* \ No newline at end of file +public/* +types/* \ No newline at end of file diff --git a/example/ts/src/client.ts b/example/ts/src/client.ts index 859aba6..3432079 100644 --- a/example/ts/src/client.ts +++ b/example/ts/src/client.ts @@ -6,7 +6,7 @@ * This file is an example of using roads router in the client */ -import { Road, RoadsPJAX, ParseBodyMiddleware, BasicRouterMiddleware, CookieMiddleware, Request } from 'roads'; +import { Road, RoadsPJAX, ParseBodyMiddleware, RouterMiddleware, CookieMiddleware, Request } from 'roads'; import applyPublicRotues from './routes/applyPublicRoutes'; import emptyTo404 from './middleware/emptyTo404'; @@ -25,7 +25,7 @@ road.use(ParseBodyMiddleware.middleware); road.use(CookieMiddleware.buildClientMiddleware(document)); pjax.register(); pjax.registerAdditionalElement(document.getElementById('home') as HTMLAnchorElement); -const router = new BasicRouterMiddleware.BasicRouter(road); +const router = new RouterMiddleware.Router(road); applyPublicRotues(router); const testRequest = new Request(false, 'localhost', 8081); diff --git a/example/ts/src/routes/applyPrivateRoutes.ts b/example/ts/src/routes/applyPrivateRoutes.ts index 9196fd7..ea31708 100644 --- a/example/ts/src/routes/applyPrivateRoutes.ts +++ b/example/ts/src/routes/applyPrivateRoutes.ts @@ -9,7 +9,7 @@ import * as fs from 'fs'; import { CookieContext } from 'roads/types/middleware/cookieMiddleware'; import { StoreValsContext } from 'roads/types/middleware/storeVals'; -import { BasicRouterMiddleware, Response } from 'roads'; +import { RouterMiddleware, Response } from 'roads'; const TITLE_KEY = 'page-title'; /** @@ -19,8 +19,8 @@ const TITLE_KEY = 'page-title'; * * @param {SimpleRouter} router - The router that the routes will be added to */ -export default function applyPrivateRotues(router: BasicRouterMiddleware.BasicRouter): void { - router.addRoute('GET', '/private', async function (this: CookieContext & StoreValsContext) { +export default function applyPrivateRotues(router: RouterMiddleware.Router): void { + router.addRoute('GET', '/private', async function () { this.storeVal(TITLE_KEY, 'Private Resource'); this.setCookie('private_cookie', 'foo', { httpOnly: true @@ -36,13 +36,13 @@ export default function applyPrivateRotues(router: BasicRouterMiddleware.BasicRo home!
`); }); - router.addRoute('GET', '/privateJSON', async function (this: StoreValsContext, ) { + router.addRoute('GET', '/privateJSON', async function () { this.storeVal('ignoreLayout', true); return new Response(JSON.stringify({'private-success': true})); }); // eslint-disable-next-line @typescript-eslint/no-unused-vars - router.addRoute('GET', 'client.js', async function (this: StoreValsContext, url, body, headers) { + router.addRoute('GET', 'client.js', async function (url, body, headers) { this.storeVal('ignoreLayout', true); // In the real world the body of the response should be created from a template engine. return new Response(fs.readFileSync(`${__dirname }/../../../public/client.js`).toString('utf-8'), 200, { diff --git a/example/ts/src/routes/applyPublicRoutes.ts b/example/ts/src/routes/applyPublicRoutes.ts index 5f146b9..69eb870 100644 --- a/example/ts/src/routes/applyPublicRoutes.ts +++ b/example/ts/src/routes/applyPublicRoutes.ts @@ -6,7 +6,7 @@ * This file is an example of how to assign some public routes to a roads server */ -import { Response, BasicRouterMiddleware } from 'roads'; +import { Response, RouterMiddleware } from 'roads'; const TITLE_KEY = 'page-title'; import { ParseBodyContext } from 'roads/types/middleware/parseBody'; @@ -24,8 +24,8 @@ interface ExampleRequestBody { * * @param {SimpleRouter} router - The router that the routes will be added to */ -export default function applyPublicRotues(router: BasicRouterMiddleware.BasicRouter): void { - router.addRoute('GET', '/', async function (this: StoreValsContext) { +export default function applyPublicRotues(router: RouterMiddleware.Router): void { + router.addRoute('GET', '/', async function () { this.storeVal(TITLE_KEY, 'Root Resource'); // In the real world the body of the response should be created from a template engine. @@ -39,7 +39,7 @@ export default function applyPublicRotues(router: BasicRouterMiddleware.BasicRou }); }); - router.addRoute('GET', '/public', async function (this: StoreValsContext & CookieContext) { + router.addRoute('GET', '/public', async function () { this.storeVal(TITLE_KEY, 'Public Resource'); console.log('Here are all cookies accessible to this code: ', this.getCookies()); console.log('Cookies are not set until you access the private route.'); @@ -59,7 +59,7 @@ export default function applyPublicRotues(router: BasicRouterMiddleware.BasicRou }); // eslint-disable-next-line @typescript-eslint/no-unused-vars - router.addRoute('POST', '/postdata', async function (this: ParseBodyContext, url, body, headers) { + router.addRoute>('POST', '/postdata', async function (url, body, headers) { console.log(`You sent the message:${this.body?.message}`); this.ignore_layout = true; return new Response('', 302, { location: '/public' }); diff --git a/example/ts/src/server.ts b/example/ts/src/server.ts index 13fc353..ca4ad01 100644 --- a/example/ts/src/server.ts +++ b/example/ts/src/server.ts @@ -7,7 +7,7 @@ */ import { Road, Response, RemoveTrailingSlashMiddleware, CookieMiddleware, - StoreValsMiddleware, ParseBodyMiddleware, BasicRouterMiddleware } from 'roads'; + StoreValsMiddleware, ParseBodyMiddleware, RouterMiddleware } from 'roads'; import { Server } from 'roads-server'; import addLayout from './middleware/addLayout'; @@ -28,7 +28,7 @@ road.use(StoreValsMiddleware.middleware); road.use(addLayout); road.use(ParseBodyMiddleware.middleware); -const router = new BasicRouterMiddleware.BasicRouter(road); +const router = new RouterMiddleware.Router(road); applyPublicRotues(router); applyPrivateRoutes(router); road.use(emptyTo404); diff --git a/example/ts/types/build.d.ts b/example/ts/types/build.d.ts deleted file mode 100644 index ab39039..0000000 --- a/example/ts/types/build.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * build.ts - * Copyright(c) 2021 Aaron Hedges - * MIT Licensed - * - * This file build the client side javascript for in browser rendering - */ -export {}; diff --git a/example/ts/types/buildClient.d.ts b/example/ts/types/buildClient.d.ts deleted file mode 100644 index 9a473e7..0000000 --- a/example/ts/types/buildClient.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * build.ts - * Copyright(c) 2021 Aaron Hedges - * MIT Licensed - * - * This file makes it easier to write browserify scripts to build roads to work in the browser - * If you want the script to watch the input file for changes provide the `--watch` flag. - */ -export {}; diff --git a/example/ts/types/client.d.ts b/example/ts/types/client.d.ts deleted file mode 100644 index 3502e2b..0000000 --- a/example/ts/types/client.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * client.ts - * Copyright(c) 2021 Aaron Hedges - * MIT Licensed - * - * This file is an example of using roads router in the client - */ -export {}; diff --git a/example/ts/types/middleware/addLayout.d.ts b/example/ts/types/middleware/addLayout.d.ts deleted file mode 100644 index 5a626e7..0000000 --- a/example/ts/types/middleware/addLayout.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * addLayout.ts - * Copyright(c) 2018 Aaron Hedges - * MIT Licensed - * - * This file is an example of how to apply HTML layouts via a middleware system - */ -import { Middleware } from 'roads/types/core/road'; -import { StoreValsContext } from 'roads/types/middleware/storeVals'; -/** - * This middleware wraps the response in a standard HTML layout. It looks for three fields in the request context. - * - _page_title - The title of the page - * - ignore_layout - If true, this middleware will not apply the layout (useful for JSON responses) - * - * @param {string} method - HTTP request method - * @param {string} url - HTTP request url - * @param {string} body - HTTP request body - * @param {object} headers - HTTP request headers - * @param {function} next - When called, this function will execute the next step in the roads method chain - */ -declare const addLayoutMiddleware: Middleware; -export default addLayoutMiddleware; diff --git a/example/ts/types/middleware/emptyTo404.d.ts b/example/ts/types/middleware/emptyTo404.d.ts deleted file mode 100644 index 23def30..0000000 --- a/example/ts/types/middleware/emptyTo404.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * emptyTo404.ts - * Copyright(c) 2021 Aaron Hedges - * MIT Licensed - * - * This file is an example of how to apply HTML layouts via a middleware system - */ -import { Middleware, Context } from 'roads/types/core/road'; -/** - * This middleware translates missing responses into 404s - * - * @param {string} method - HTTP request method - * @param {string} url - HTTP request url - * @param {string} body - HTTP request body - * @param {object} headers - HTTP request headers - * @param {function} next - When called, this function will execute the next step in the roads method chain - */ -declare const emptyTo404: Middleware; -export default emptyTo404; diff --git a/example/ts/types/routes/applyPrivateRoutes.d.ts b/example/ts/types/routes/applyPrivateRoutes.d.ts deleted file mode 100644 index f9dd77d..0000000 --- a/example/ts/types/routes/applyPrivateRoutes.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * applyPrivateRoutes.ts - * Copyright(c) 2018 Aaron Hedges - * MIT Licensed - * - * This file is an example of how to assign some private routes to a road server - */ -import { BasicRouterMiddleware } from 'roads'; -/** - * Before calling this function you should create your roads object and bind a SimpleRouter to that road. - * You then pass the road to this function to assign a collection of example routes that should only - * be rendered on the server. - * - * @param {SimpleRouter} router - The router that the routes will be added to - */ -export default function applyPrivateRotues(router: BasicRouterMiddleware.BasicRouter): void; diff --git a/example/ts/types/routes/applyPublicRoutes.d.ts b/example/ts/types/routes/applyPublicRoutes.d.ts deleted file mode 100644 index 93d5b2e..0000000 --- a/example/ts/types/routes/applyPublicRoutes.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * applyPublicRoutes.ts - * Copyright(c) 2018 Aaron Hedges - * MIT Licensed - * - * This file is an example of how to assign some public routes to a roads server - */ -import { BasicRouterMiddleware } from 'roads'; -/** - * Before calling this function you should create your roads object and bind a SimpleRouter to that road. - * You then pass the road to this function to assign a collection of example routes that will be rendered - * on both the client and the server - * - * @param {SimpleRouter} router - The router that the routes will be added to - */ -export default function applyPublicRotues(router: BasicRouterMiddleware.BasicRouter): void; diff --git a/example/ts/types/server.d.ts b/example/ts/types/server.d.ts deleted file mode 100644 index 5d0b137..0000000 --- a/example/ts/types/server.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * server.ts - * Copyright(c) 2021 Aaron Hedges - * MIT Licensed - * - * This file starts up the HTTP roads server - */ -export {}; diff --git a/package.json b/package.json index 685d3e9..61b8a0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "roads", - "version": "8.0.0-alpha.1", + "version": "8.0.0-alpha.2", "author": { "name": "Aaron Hedges", "email": "aaron@dashron.com", diff --git a/src/index.ts b/src/index.ts index 0c0cda6..4e5ea79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,4 +11,4 @@ export * as ParseBodyMiddleware from './middleware/parseBody'; export * as RerouteMiddleware from './middleware/reroute'; export * as StoreValsMiddleware from './middleware/storeVals'; export * as ModifiedSinceMiddleware from './middleware/modifiedSince'; -export * as BasicRouterMiddleware from './middleware/basicRouter'; \ No newline at end of file +export * as RouterMiddleware from './middleware/router'; \ No newline at end of file diff --git a/src/middleware/basicRouter.ts b/src/middleware/router.ts similarity index 86% rename from src/middleware/basicRouter.ts rename to src/middleware/router.ts index 55f9620..fe9e4f9 100644 --- a/src/middleware/basicRouter.ts +++ b/src/middleware/router.ts @@ -1,9 +1,9 @@ /** - * basicRouter.ts + * router.ts * Copyright(c) 2021 Aaron Hedges * MIT Licensed * - * This is a basic router middleware for roads. + * This is a router middleware for roads. * It allows you to easily attach functionality to HTTP methods and paths. */ @@ -15,7 +15,7 @@ import { NextCallback, RequestChain } from '../core/requestChain'; export interface Route { - (this: ContextType, method: string, path: BasicRouterURL, body: string, + (this: ContextType, method: string, path: RouterURL, body: string, headers: IncomingHeaders, next: NextCallback): Promise } @@ -25,14 +25,14 @@ interface RouteDetails { method: string } -export interface BasicRouterURL extends ReturnType { +export interface RouterURL extends ReturnType { args?: Record } /** - * This is a basic router middleware for roads. - * You can assign functions to url paths, and those paths can have some very basic variable templating + * This is a router middleware for roads. + * You can assign functions to url paths, and those paths can have variable templating * - * Templating is basic. Each URI is considered to be a series of "path parts" separated by slashes. + * There are only a couple of template options. Each URI is considered to be a series of "path parts" separated by slashes. * If a path part starts with a #, it is assumed to be a numeric variable. Non-numbers will not match this route * If a path part starts with a $, it is considered to be an alphanumeric variabe. * All non-slash values will match this route. @@ -43,13 +43,13 @@ export interface BasicRouterURL extends ReturnType { * /users/#user_id will match /users/12345, not /users/abcde. If a request is made to /users/12345 * the route's requestUrl object will contain { args: {user_id: 12345}} along with all other url object values * - * @name BasicRouter + * @name Router */ -export class BasicRouter { +export class Router { protected _routes: RouteDetails[]; /** - * @param {Road} [road] - The road that will receive the BasicRouter middleware + * @param {Road} [road] - The road that will receive the Router middleware */ constructor (road?: Road) { this._routes = []; @@ -63,15 +63,15 @@ export class BasicRouter { * If you don't provide a road to the SimpleRouter constructor, your routes will not be executed. * If you have reason not to assign the road off the bat, you can assign it later with this function. * - * @param {Road} road - The road that will receive the BasicRouter middleware + * @param {Road} road - The road that will receive the Router middleware */ applyMiddleware (road: Road): void { // We need to alias because "this" for the middleware function must - // be the this applied by road.use, not the BasicRouter + // be the this applied by road.use, not the Router // eslint-disable-next-line @typescript-eslint/no-this-alias const _self = this; - // We do this to ensure we have access to the BasicRouter once we lose this due to road's context + // We do this to ensure we have access to the Router once we lose this due to road's context road.use((function (request_method, request_url, request_body, request_headers, next) { return _self._middleware.call(this, _self._routes, request_method, request_url, request_body, request_headers, next); @@ -82,7 +82,7 @@ export class BasicRouter { * This is where you want to write the majority of your webservice. The `fn` parameter should contain * the actions you want to perform when a certain `path` and HTTP `method` are accessed via the `road` object. * - * The path supports a very basic templating system. The values inbetween each slash can be interpreted + * The path supports a templating system. The values inbetween each slash can be interpreted * in one of three ways * - If a path part starts with a #, it is assumed to be a numeric variable. Non-numbers will not match this route * - If a path part starts with a $, it is considered to be an alphanumeric variabe. All non-slash values @@ -99,8 +99,10 @@ export class BasicRouter { * @param {(string|array)} paths - One or many URL paths that will trigger the provided function * @param {function} fn - The function containing all of your route logic */ - addRoute ( - method: string, paths: string | string[], fn: Route | Route[] + addRoute ( + method: string, + paths: string | string[], + fn: Route | Route[] ): void { if (!Array.isArray(paths)) { paths = [paths]; @@ -201,7 +203,7 @@ export class BasicRouter { /** * Checks to see if the route matches the request, and if true assigns any applicable url variables and returns the route * - * @param {object} route - Route object from this basic router class + * @param {object} route - Route object from this router class * @param {object} route.method - HTTP method associated with this route * @param {object} route.path - HTTP path associated with this route * @param {object} request_url - Parsed HTTP request url @@ -240,14 +242,14 @@ function compareRouteAndApplyArgs (route: {method: string, path: string}, reques } // TODO: get rid of this `as` - applyArg(request_url as BasicRouterURL, template_part.substring(1), Number(actual_part)); + applyArg(request_url as RouterURL, template_part.substring(1), Number(actual_part)); continue; } if (template_part[0] === '$') { // $ templates accept any non-slash alphanumeric character // TODO: get rid of this `as` - applyArg(request_url as BasicRouterURL, template_part.substring(1), String(actual_part)); + applyArg(request_url as RouterURL, template_part.substring(1), String(actual_part)); // Continue so that continue; } @@ -270,7 +272,7 @@ function compareRouteAndApplyArgs (route: {method: string, path: string}, reques * @param {string} template_part - The template variable * @param {*} actual_part - The url value */ -function applyArg(request_url: BasicRouterURL, template_part: string, actual_part: string | number): void { +function applyArg(request_url: RouterURL, template_part: string, actual_part: string | number): void { if (typeof(request_url.args) === 'undefined') { request_url.args = {}; } diff --git a/test/__tests__/middleware/basicRouter.test.ts b/test/__tests__/middleware/basicRouter.test.ts index 03f4c9c..f491905 100644 --- a/test/__tests__/middleware/basicRouter.test.ts +++ b/test/__tests__/middleware/basicRouter.test.ts @@ -1,6 +1,6 @@ import parse from 'url-parse'; -import { BasicRouter, Route, BasicRouterURL } from '../../../src/middleware/basicRouter'; +import { Router, Route, RouterURL } from '../../../src/middleware/router'; import Road from '../../../src/core/road'; import Response from '../../../src/core/response'; import { Context } from '../../../src/core/road'; @@ -10,14 +10,14 @@ import { NextCallback } from '../../../src/core/requestChain'; const router_file_test_path = `${__dirname }/../../resources/_router_file_test.js`; -describe('Basic Router Tests', () => { +describe('Router Tests', () => { /** * */ test('test addRoute adds values to the list of routes in the right format', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; const fn: Route = () => { return Promise.resolve(new Response(''));}; @@ -37,7 +37,7 @@ describe('Basic Router Tests', () => { expect.assertions(1); const road = new Road(); - const router = new BasicRouter(); + const router = new Router(); router.applyMiddleware(road); expect(road['_request_chain'].length()).toEqual(1); @@ -49,7 +49,7 @@ describe('Basic Router Tests', () => { test('test middleware function routes successfully to successful routes', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; let route_hit = false; @@ -71,7 +71,7 @@ describe('Basic Router Tests', () => { test('test middleware function 405s when route exists but method is not present', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const next: NextCallback = () => { @@ -86,7 +86,7 @@ describe('Basic Router Tests', () => { test('test middleware function routes successfully to successful routes with x-http-method-override header', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'POST'; let route_hit = false; @@ -111,7 +111,7 @@ describe('Basic Router Tests', () => { test('test middleware function routes ignores x-http-method-override header on GET requests', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; let route_hit = false; @@ -136,7 +136,7 @@ describe('Basic Router Tests', () => { test('test middleware function routes successfully to successful routes with _method query param', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'POST'; let route_hit = false; @@ -159,7 +159,7 @@ describe('Basic Router Tests', () => { test('test middleware function routes successfully ignores _method query param on GET requests', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; let route_hit = false; @@ -186,7 +186,7 @@ describe('Basic Router Tests', () => { test(`test middleware function routes successfully to successful routes only once when there may be more than one route`, () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; let route_hit = false; @@ -216,7 +216,7 @@ describe('Basic Router Tests', () => { */ test('test middleware function routes to next on a missed url', () => { expect.assertions(2); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; let route_hit = false; @@ -241,7 +241,7 @@ describe('Basic Router Tests', () => { */ test('test middleware function routes to next on a missed http method but matching url', () => { expect.assertions(2); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; let route_hit = false; @@ -267,7 +267,7 @@ describe('Basic Router Tests', () => { test('test route function with no template gets the proper context and arguments', () => { expect.assertions(4); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; const body = '{"harvey": "birdman"}'; @@ -297,7 +297,7 @@ describe('Basic Router Tests', () => { */ test('test route function with numeric template gets the proper context and arguments', () => { expect.assertions(4); - const router = new BasicRouter(); + const router = new Router(); const path = '/#numeric'; const req_path = '/12345'; const method = 'GET'; @@ -307,7 +307,7 @@ describe('Basic Router Tests', () => { const route: Route = (request_method, request_url, request_body, request_headers) => { expect(request_method).toEqual(method); // parsed url - const parsed_url: BasicRouterURL = parse(req_path, true); + const parsed_url: RouterURL = parse(req_path, true); parsed_url.args = {numeric: 12345}; expect(request_url).toEqual(parsed_url); // passthrough request body @@ -330,7 +330,7 @@ describe('Basic Router Tests', () => { */ test('test route function with string template gets the proper context and arguments', () => { expect.assertions(4); - const router = new BasicRouter(); + const router = new Router(); const path = '/$string'; const req_path = '/hello'; const method = 'GET'; @@ -340,7 +340,7 @@ describe('Basic Router Tests', () => { const route: Route = (request_method, request_url, request_body, request_headers) => { expect(request_method).toEqual(method); // parsed url - const parsed_url: BasicRouterURL = parse(req_path, true); + const parsed_url: RouterURL = parse(req_path, true); parsed_url.args = {string: 'hello'}; expect(request_url).toEqual(parsed_url); // passthrough request body @@ -362,7 +362,7 @@ describe('Basic Router Tests', () => { */ test('test route that throws an exception is handled properly', () => { expect.assertions(1); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; const error_message = 'blah blah blah'; @@ -383,7 +383,7 @@ describe('Basic Router Tests', () => { */ test('test route successfully returns value out of the middleware', () => { expect.assertions(2); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; const fn: Route = () => { @@ -408,7 +408,7 @@ describe('Basic Router Tests', () => { */ test('test next successfully returns value out of the middleware', () => { expect.assertions(2); - const router = new BasicRouter(); + const router = new Router(); const path = '/'; const method = 'GET'; const fn: Route = () => { @@ -436,7 +436,7 @@ describe('Basic Router Tests', () => { expect.assertions(1); const road = new Road(); - const router = new BasicRouter(); + const router = new Router(); router.applyMiddleware(road); const path = '/'; @@ -460,7 +460,7 @@ describe('Basic Router Tests', () => { expect.assertions(1); const road = new Road(); - const router = new BasicRouter(); + const router = new Router(); router.applyMiddleware(road); const path = '/'; @@ -481,7 +481,7 @@ describe('Basic Router Tests', () => { expect.assertions(5); const road = new Road(); - const router = new BasicRouter(); + const router = new Router(); router.applyMiddleware(road); return router.addRouteFile(router_file_test_path) @@ -510,7 +510,7 @@ describe('Basic Router Tests', () => { test('test routes loaded from a file with prefix', () => { expect.assertions(5); const road = new Road(); - const router = new BasicRouter(); + const router = new Router(); router.applyMiddleware(road); return router.addRouteFile(router_file_test_path, '/test_prefix') @@ -538,7 +538,7 @@ describe('Basic Router Tests', () => { test('test routes using a request chain successfully progress through the chain', () => { expect.assertions(3); const road = new Road(); - const router = new BasicRouter(); + const router = new Router(); router.applyMiddleware(road); const path = '/'; diff --git a/todo.md b/todo.md index 9724294..1c28610 100644 --- a/todo.md +++ b/todo.md @@ -1,3 +1,9 @@ +1. Fix documentation + 1. Method is now part of the route function + 2. Ensure browserify is entirely gone from all examples + 3. Document the router request chain + 4. Document the new context typing + # Future 1. Figure out a way to have better typing on headers 2. Ensure we have JS and Typescript examples for everything.