Skip to content

b4dnewz/micro-fs-router

Repository files navigation

micro-fs-router

A micro plugin that leverage the filesystem

NPM version Build Status Coverage percentage

Features

  • Works out of the box with zero config
  • Automatically parse request query, params and body
  • Can be extended with a compose function
  • Support route params, nested routes, ...

Getting started

Install the project using your favourite package manager.

npm install micro-fs-router

Import the module in your main script and run it with the routes path.

import microFsRouter from "micro-fs-router";

const router = microFsRouter("./routes");

export default router;

Inside the routes folder a file called hello.js with a micro function.

export default function({ query }) {
    return `Hello, ${query.name || "micro"}`;
}

Now run it with micro and try to access the service.

$ npx micro index.js
$ curl http://localhost:3000/hello
Hello, micro

$ curl http://localhost:3000/hello?name=test
Hello, test

Contributing

  1. Create an issue and describe your idea
  2. Fork the project (https://github.com/b4dnewz/micro-fs-router/fork)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes with logic (git commit -am 'Add some feature')
  5. Publish the branch (git push origin my-new-feature)
  6. Add some test for your new feature
  7. Create a new Pull Request

License

Made with love and MIT license © Filippo Conti