auto-use-routes

1.0.5 • Public • Published

Installation

npm install auto-use-routes --save

Usage

directory structure

api/  
    aaa.js  
    bbb.get.js  
    ccc.post.js  
    test1/index.js  
    test2/[xxx].get.js  
    test3/[...xxx].get.js  

api/aaa.js

export default (req,res)=>{  
    res.end("works");  
}  

express

import express from 'express'  
import loadRouter from 'auto-use-routes'
import path from 'path'
const app = express()
let router = await loadRouter(express.Router(),path.join(path.resolve(),'/api'),{printlog:true})
app.use('/api',router)
app.listen(3000);

fastify

import loadRouter from 'auto-use-routes'  
.....  
let plugin = async(fastify, opts, done)=> {  
    await loadRouter(fastify,path.join(path.resolve(),'./server/api'),{printlog:true});  
}  
fastify.register(plugin, {prefix: '/api'})

Package Sidebar

Install

npm i auto-use-routes

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

4.37 kB

Total Files

3

Last publish

Collaborators

  • andy1561