From 272fda47801d711e70f88fde4cce081972f56eee Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 4 Jan 2025 09:32:18 +0100 Subject: [PATCH] chore: rename SVRouter to SVRRouter due to npm publishing issues --- .github/workflows/main.yml | 2 +- README.md | 38 +++++++++++++++++++------------------- package-lock.json | 4 ++-- package.json | 4 ++-- src/index.js | 30 +++++++++++++++--------------- tests/index.test.js | 16 ++++++++-------- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1611e47..c99e333 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,6 @@ jobs: fetch-depth: 0 - uses: spyoungtech/mirror-action@v0.5.1 with: - REMOTE: "https://git.svrjs.org/svrjs/svrouter.git" + REMOTE: "https://git.svrjs.org/svrjs/svrrouter.git" GIT_USERNAME: github-mirror GIT_PASSWORD: ${{ secrets.GIT_PASSWORD }} diff --git a/README.md b/README.md index d697448..7434c19 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# SVRouter +# SVRRouter -SVRouter is a router library built for use in building web applications as SVR.JS 4.x mods. +SVRRouter is a router library built for use in building web applications as SVR.JS 4.x mods. -Example SVR.JS mod that uses SVRouter (you will need to install the `svrouter` npm package either in the SVR.JS installation root or globally): +Example SVR.JS mod that uses SVRRouter (you will need to install the `svrrouter` npm package either in the SVR.JS installation root or globally): ```js -const svrouter = require("svrouter"); -const router = svrouter(); +const svrrouter = require("svrrouter"); +const router = svrrouter(); // eslint-disable-next-line no-unused-vars router.get("/hello", (req, res, logFacilities, config, next) => { @@ -20,18 +20,18 @@ router.get("/hello", (req, res, logFacilities, config, next) => { module.exports = router; module.exports.modInfo = { - name: "Example mod with SVRouter", + name: "Example mod with SVRRouter", version: "0.0.0" }; ``` -## Methods (exported by the `svrouter` package) +## Methods (exported by the `svrrouter` package) -### _svrouter()_ +### _svrrouter()_ -Returns: the SVRouter router, which is a SVR.JS mod function with additional functions for adding routes and middleware. +Returns: the SVRRouter router, which is a SVR.JS mod function with additional functions for adding routes and middleware. -## Methods (provided by the SVRouter router) +## Methods (provided by the SVRRouter router) ### _router(req, res, logFacilities, config, next)_ @@ -51,9 +51,9 @@ Parameters: - _path_ - the route path (begins with "/"), for which the route applies. The route paths are process via the [`path-to-regexp` library](https://www.npmjs.com/package/path-to-regexp) (_String_) - _callback_ - the SVR.JS mod callback applied for the route (_Function_) -Returns: the SVRouter router (so that you can chain the methods for adding routes or pass-throughs) +Returns: the SVRRouter router (so that you can chain the methods for adding routes or pass-throughs) -The function adds a route to the SVRouter router. +The function adds a route to the SVRRouter router. If the _method_ parameter is `"*"`, the route will apply to all the methods @@ -66,7 +66,7 @@ The _callback_ parameter has these arguments of the SVR.JS mod callback: The _req_ object has an additional _params_ property, which contains request parameters, for example if the request URL is `/api/task/1`, and the route path is `/api/task/:id`, then the _req.params_ object is a `null` prototype object with the `id` property set to `"1"`. -The _req_ object has another additional _svrouterBase_ property, which contains the route base used internally by a SVRouter router. It's not recommended to override this property, as doing it may result in a SVRouter router behaving erratically. +The _req_ object has another additional _svrrouterBase_ property, which contains the route base used internally by a SVRRouter router. It's not recommended to override this property, as doing it may result in a SVRRouter router behaving erratically. You can read more about the SVR.JS mod callbacks in the [SVR.JS mod API documentation](https://svrjs.org/docs/api/svrjs-api). @@ -74,11 +74,11 @@ You can read more about the SVR.JS mod callbacks in the [SVR.JS mod API document Parameters: - _path_ - the path (begins with "/"), for which the route applies. (optional, _String_) - - _callback_ - the SVR.JS mod callback, which the SVRouter router will pass to (_Function_) + - _callback_ - the SVR.JS mod callback, which the SVRRouter router will pass to (_Function_) -Returns: the SVRouter router (so that you can chain the methods for routes or pass-throughs) +Returns: the SVRRouter router (so that you can chain the methods for routes or pass-throughs) -The function adds a pass-through (can be middleware) to the SVRouter router. The pass-through can be to an another SVRouter router (the request URLs relative to a parent route need to be provided for the _router.route_ function in the SVRouter router). +The function adds a pass-through (can be middleware) to the SVRRouter router. The pass-through can be to an another SVRRouter router (the request URLs relative to a parent route need to be provided for the _router.route_ function in the SVRRouter router). The _callback_ parameter has these arguments of the SVR.JS mod callback: - _req_ - the SVR.JS request object @@ -87,7 +87,7 @@ The _callback_ parameter has these arguments of the SVR.JS mod callback: - _config_ - the SVR.JS configuration object - _next_ - the callback which passes the execution to other routes, SVR.JS mods and SVR.JS internal handlers. -The _req_ object has an additional _svrouterBase_ property, which contains the route base used internally by a SVRouter router. It's not recommended to override this property, as doing it may result in a SVRouter router behaving erratically. +The _req_ object has an additional _svrrouterBase_ property, which contains the route base used internally by a SVRRouter router. It's not recommended to override this property, as doing it may result in a SVRRouter router behaving erratically. You can read more about the SVR.JS mod callbacks in the [SVR.JS mod API documentation](https://svrjs.org/docs/api/svrjs-api). @@ -97,9 +97,9 @@ Parameters: - _path_ - the path (begins with "/"), for which the route applies. (optional, _String_) - _middleware_ - the middleware compatible with the `router` library (_Function_) -Returns: the SVRouter router (so that you can chain the methods for routes or pass-throughs) +Returns: the SVRRouter router (so that you can chain the methods for routes or pass-throughs) -The function adds middleware compatible with the `router` library to the SVRouter router. Middleware that depends on Express's request and response properties may not work. +The function adds middleware compatible with the `router` library to the SVRRouter router. Middleware that depends on Express's request and response properties may not work. The _middleware_ parameter has these arguments of middleware compatible with the `router` library: - _req_ - the request object diff --git a/package-lock.json b/package-lock.json index 2018fb4..0d3c18e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "svrouter", + "name": "svrrouter", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "svrouter", + "name": "svrrouter", "version": "0.0.0", "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 62d86a4..c81aac8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "svrouter", + "name": "svrrouter", "version": "0.0.0", "description": "A router library for SVR.JS 4.x mods", "main": "dist/index.js", @@ -14,7 +14,7 @@ }, "repository": { "type": "git", - "url": "https://git.svrjs.org/svrjs/svrouter.git" + "url": "https://git.svrjs.org/svrjs/svrrouter.git" }, "keywords": [ "routing", diff --git a/src/index.js b/src/index.js index b275b12..24ad050 100644 --- a/src/index.js +++ b/src/index.js @@ -1,27 +1,27 @@ const { match } = require("path-to-regexp"); const http = require("http"); -function svrouter() { +function svrrouter() { const routes = []; const router = (req, res, logFacilities, config, next) => { let index = 0; let previousReqParams = req.params; - let previousReqSvrouterBase = req.svrouterBase; + let previousReqSvrouterBase = req.svrrouterBase; let paramsPresent = false; let passPathPresent = false; const nextRoute = () => { if (paramsPresent) req.params = previousReqParams; - if (passPathPresent) req.svrouterBase = previousReqSvrouterBase; + if (passPathPresent) req.svrrouterBase = previousReqSvrouterBase; let currentRoute = routes[index++]; let currentMatch = currentRoute && currentRoute.pathFunction ? currentRoute.pathFunction( req.parsedURL.pathname.substring( - (req.svrouterBase ? req.svrouterBase : "").length + (req.svrrouterBase ? req.svrrouterBase : "").length ) ) - : false; // Let's assume the request URL begins with the contents of the req.svrouterBase property. + : false; // Let's assume the request URL begins with the contents of the req.svrrouterBase property. while ( currentRoute && ((currentRoute.method && req.method != currentRoute.method) || @@ -32,7 +32,7 @@ function svrouter() { currentRoute && currentRoute.pathFunction ? currentRoute.pathFunction( req.parsedURL.pathname.substring( - (req.svrouterBase ? req.svrouterBase : "").length + (req.svrrouterBase ? req.svrrouterBase : "").length ) ) : false; @@ -47,8 +47,8 @@ function svrouter() { ? currentMatch.params : Object.create(null); if (passPathPresent) - req.svrouterBase = - (req.svrouterBase ? req.svrouterBase : "") + + req.svrrouterBase = + (req.svrrouterBase ? req.svrrouterBase : "") + currentRoute.passPath; currentRoute.callback(req, res, logFacilities, config, nextRoute); } catch (err) { @@ -122,20 +122,20 @@ function svrouter() { const previousReqBaseUrl = req.baseUrl; const previousReqUrl = req.url; const previousReqOriginalUrl = req.originalUrl; - const previousReqSvrouterBase = req.svrouterBase; + const previousReqSvrouterBase = req.svrrouterBase; - const svrouterBase = req.svrouterBase ? req.svrouterBase : ""; - req.baseUrl = svrouterBase; + const svrrouterBase = req.svrrouterBase ? req.svrrouterBase : ""; + req.baseUrl = svrrouterBase; req.originalUrl = req.url; - req.url = req.url.substr(svrouterBase.length); // Let's assume the request URL begins with the contents of svrouterBase variable. + req.url = req.url.substr(svrrouterBase.length); // Let's assume the request URL begins with the contents of svrrouterBase variable. if (!req.url) req.url = "/"; - req.svrouterBase = undefined; + req.svrrouterBase = undefined; const nextCallback = () => { req.baseUrl = previousReqBaseUrl; req.url = previousReqUrl; req.originalUrl = previousReqOriginalUrl; - req.svrouterBase = previousReqSvrouterBase; + req.svrrouterBase = previousReqSvrouterBase; next(); }; @@ -162,4 +162,4 @@ function svrouter() { return router; } -module.exports = svrouter; +module.exports = svrrouter; diff --git a/tests/index.test.js b/tests/index.test.js index aa0dcb1..b96a669 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -1,10 +1,10 @@ -const svrouter = require("../src/index.js"); +const svrrouter = require("../src/index.js"); -describe("SVRouter", () => { +describe("SVRRouter", () => { let router; beforeEach(() => { - router = svrouter(); + router = svrrouter(); }); test("should add and handle a GET route", () => { @@ -313,7 +313,7 @@ describe("SVRouter", () => { }); test("should handle nested routers correctly", () => { - const childRouter = svrouter(); + const childRouter = svrrouter(); const req = { method: "GET", @@ -338,7 +338,7 @@ describe("SVRouter", () => { }); test("should fallback to parent router if no route matches in child router", () => { - const childRouter = svrouter(); + const childRouter = svrrouter(); const req = { method: "GET", @@ -364,7 +364,7 @@ describe("SVRouter", () => { }); test("should handle parameterized routes in nested routers", () => { - const childRouter = svrouter(); + const childRouter = svrrouter(); const req = { method: "GET", @@ -389,8 +389,8 @@ describe("SVRouter", () => { }); test("should handle multiple nested routers", () => { - const childRouter1 = svrouter(); - const childRouter2 = svrouter(); + const childRouter1 = svrrouter(); + const childRouter2 = svrrouter(); const req = { method: "GET",