npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-dir-router

v1.1.6

Published

A middleware of KOA, which supports the access form of folder directory as web address, and does not need to restart the koa service, it can hot update the file code inside the folder, modify it and go online. It is convenient to modify the code and go on

Downloads

17

Readme

koa-dir-routerNPM version

中文文档

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

Installation

$ npm install koa-dir-router

Options

  • 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 with prefixurl;

Example

Start in the same level directory of the startup program

directory structure

·
├──index.js
├──controller
   ├──mis
      ├──type.js
// ./controller/mis/type.js
module.exports = function (ctx) {
  ctx.body = `show-ok`
}
// ./index.js
const dirRouter = require('koa-dir-router')
const Koa = require('koa')
const path = require('path')
var app = new Koa()

app.use(
  dirRouter({
    dir: path.join(__dirname, './controller'), // Incoming directory structure to access
  })
)
app.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:

$ GET /mis/type

show-ok

showOK.png

If you need a base address baseUrl

// ./index.js
const dirRouter = require('koa-dir-router')
const Koa = require('koa')
const path = require('path')
var app = new Koa()

app.use(
  dirRouter({
    dir: path.join(__dirname, './controller'), // Incoming directory structure to access
    baseUrl: '/mis', // base address
  })
)
app.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:

$ GET /mis/mis/type

show-ok

showOK2.pngWhen something goes wrong with the code?

If there is something wrong with the code during development, 'koa dir router' will have a friendly prompt

error.png

If it is online code, you can use 'errorlog' to get it.

** set the specified transmission mode (1.1.6 +)**

Set the parameter acceptmethods to specify the program to work in a specific transmission mode

** specify different execution method bodies for different request methods (1.1.6 +)**

You can use it in the code filectx.dirRouter.MethodsNameMethod 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

module.exports = async function (ctx) {
  await ctx.dirRouter.get((c) => {
    console.log('run Get')
  })
  await ctx.dirRouter.post((c) => {
    console.log('run POST')
  })
}

License

MIT