2.0.0 • Published 1 year ago

@aaronburt/bunhost v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Router

This is a simple router for creating dynamic and static routes in a TypeScript Node.js application using NodeNext

Features Create dynamic routes for HTTP methods: GET, POST, PUT, DELETE Create static routes for serving files Uses mime library to set the correct Content-Type header for static files Usage Setting up the router Create an instance of the Router class:

import Router from './router';
const router = new Router();

Creating dynamic routes

Use the get, post, put, and delete methods to create dynamic routes:

router.get('/users', (request: Request) => {
  // handle GET request to '/users' route
  return new Response('Success');
});

router.post('/users', (request: Request) => {
  // handle POST request to '/users' route
  return new Response('Success');
});

Creating static routes

Use the addStatic method to create a static route for serving a file:

router.addStatic('/images/fileName', './images/fileName');

This will create a route that serves the file located at ./images/fileName when a request is made to /images/:fileName.

Use the listen method to start the server:

router.listen(3000);

This will start the server on port 3000.

2.0.0

1 year ago

1.0.0

1 year ago