Gathering detailed insights and metrics for koa-dir-router
Gathering detailed insights and metrics for koa-dir-router
A middleware of KOA supports the access form with folder directory as the URL, and does not need to restart koa service. It can update the file code of the folder inside the folder and modify it. It is convenient to modify the code and go online without feeling when developing the interface.
npm install koa-dir-router
Typescript
Module System
Node Version
NPM Version
69.3
Supply Chain
98.7
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
2,178
Last Day
1
Last Week
18
Last Month
52
Last Year
258
3 Stars
42 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.6
Package Id
koa-dir-router@1.1.6
Unpacked Size
15.20 kB
Size
5.63 kB
File Count
7
NPM Version
6.10.0
Node Version
10.15.1
Cumulative downloads
Total Downloads
Last day
-66.7%
1
Compared to previous day
Last week
-18.2%
18
Compared to previous week
Last month
33.3%
52
Compared to previous month
Last year
-2.6%
258
Compared to previous year
1
A middleware of KOA supports the access form with folder directory as the URL, and does not need to restart koa service. It can update the file code of the folder inside the folder and modify it. It is convenient to modify the code and go online without feeling when developing the interface.
You can use other middleware or define page mix. Koa dir router only works when ctx.response.status===404
$ npm install koa-dir-router
dir
The absolute path to the directory where the code is stored, must [String]
prefixUrl
the prefix of the request path, which is used to match the local file. The default value is'/' [String]
checkTimes
Time to detect file changes, in MS; default is 1000
[Number]
errorLog
Code method caught when the file code under the file directory executes an exception; the received value is [Function]({path,des,error})
page404
When the file code in the file directory does not exist, the callback function receives a value of [function](ctx)
debug
Whether to display debugging information; the default value is true
, the received value is [Boolean]
-The parameter acceptmethods
[string]
supports setting the accepted method. The default value is '*', and the specification is' get, post '(1.1.6 +)-The parameter httpmethod
[array]
supports extended detection. The default method supported is[get, post, put, delete]
(1.1.6 +)
In version 1.0.7, the
baseurl
parameter name is abolished and replaced withprefixurl
;
Start in the same level directory of the startup program
directory structure
·
├──index.js
├──controller
├──mis
├──type.js
1// ./controller/mis/type.js 2module.exports = function (ctx) { 3 ctx.body = `show-ok` 4} 5// ./index.js 6const dirRouter = require('koa-dir-router') 7const Koa = require('koa') 8const path = require('path') 9var app = new Koa() 10 11app.use( 12 dirRouter({ 13 dir: path.join(__dirname, './controller'), // Incoming directory structure to access 14 }) 15) 16app.listen(3000)
When accessing http://localhost:3000/mis/type, it will correspond to the file code of ./controller/MIS/type.JS
under the corresponding file directory
yields:
1$ GET /mis/type 2 3show-ok
If you need a base address baseUrl
1// ./index.js 2const dirRouter = require('koa-dir-router') 3const Koa = require('koa') 4const path = require('path') 5var app = new Koa() 6 7app.use( 8 dirRouter({ 9 dir: path.join(__dirname, './controller'), // Incoming directory structure to access 10 baseUrl: '/mis', // base address 11 }) 12) 13app.listen(3000)
When accessing http://localhost:3000/mis/mis/type, it will correspond to the file code of ./controller/MIS/type.JS
under the corresponding file directory
yields:
1$ GET /mis/mis/type 2 3show-ok
, When something goes wrong with the code?
If there is something wrong with the code during development, 'koa dir router' will have a friendly prompt
If it is online code, you can use 'errorlog' to get it.
Set the parameter acceptmethods
to specify the program to work in a specific transmission mode
You can use it in the code filectx.dirRouter.MethodsName
Method to specify the code body that is not used in different ways. The value range of methodsname is the file code httpmethod
, provided that the mode is allowed to enter the main program with acceptmethods
;
In this way, developers can quickly process the program in different ways
1module.exports = async function (ctx) { 2 await ctx.dirRouter.get((c) => { 3 console.log('run Get') 4 }) 5 await ctx.dirRouter.post((c) => { 6 console.log('run POST') 7 }) 8}
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More