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

auto2http

v0.0.3

Published

Fun gadgets -> automatically generate http files to generate express routes based on the path

Downloads

9

Readme

auto2http

webStorm根据配置来自动生产 xx.http文件 用于对接口的测试 只能在node项目中使用 WebStorm automatically produces the xx.http file according to the configuration. It is used to test the API. It can only be used in the nodejs project.

const Auto2http = require("auto2http")
const path = require('path')
const route = Auto2http.createApiDict(path.join(__dirname, '../api'), true) 
/* path.join(__dirname, '../api ') 
  接口文件的根目录  为绝对路径  
  The root directory of the interface file is an absolute path
*/
// true   是否自动生成提示  routes属性的提示
//        Whether to automatically generate a prompt for the routes attribute

仅仅是因为要生成导出是有代码提示

main.configApiList([{}])  
  
// Just because there is a code hint to generate the export

main函数

给app加路由配置 app.method(path,method)

Auto2http.main({    httpRoot: path.join(__dirname, "/dd"), // 成 http文件 的绝对路径  The absolute path of the http file
                    port: 8080,  // 端口 
                    hostname: "localhost", // 主机名
                    defaultHeader: {}, // 设置头  默认"Content-Type": "application/json","Accept": "application/json"
                    flag: "a+",   // w 或 a+ 文件写入的mode  默认a+  传 false或undefined 就不会去 写入 http文件 
                    apiList: [{  // 路由 list
                        method: "post", // 请求方式
                        path: "/msa", // 路径
                        dynamic : {// 动态路由 Dynamic routing
                            path:"/:name",
                            test:"/lisa"
                                 }, 
                        headers: { // 头
                            "Content-Type": "application/json"
                        },
                        params: { // 查询字符串
                            name: "丽萨"
                        },
                        data: { // data
                            
                        },
                        description: "测试",
                        handler: route["/msa"], // 默认会调用对应的文件中的[this.method]  This will require glad of [this.method] 
                        port: 8081,  // 独立的端口
                        hostname: "localhost", // 独立的主机名
                        plugins:{} // 独立的插件 Standalone plugin
                    }],
}).createApi({    // 完成 app.method(path,()=>{})的操作   express()
      app: express(),
      plugins: { // 每个文件导入公共的插件
          // 在接口文件中调用
      },
      callback(app) {  // 在配置路由前对app进行配置   Configure the app before configuring routing
         app.use(express.json)  
      },
      
  }).listen(8087)

路由编写

// 接口文件
//  api/ msa.js
module.exports = (plugin) => {
    return {
        post: (req, res) => {
            res.json({
                msa: 'post'
            })
        },
        get: (req, res) => {
            res.json({
                msa: 'get'
            })
        },
        ws: (req, res) => {

        }
    }
}