Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonnyjong/http-matcher
Simple wrapper for node:http to handle different page requests by using matcher and responder.
https://github.com/jonnyjong/http-matcher
Last synced: about 1 month ago
JSON representation
Simple wrapper for node:http to handle different page requests by using matcher and responder.
- Host: GitHub
- URL: https://github.com/jonnyjong/http-matcher
- Owner: JonnyJong
- License: mit
- Created: 2023-12-20T08:20:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-22T04:39:29.000Z (about 1 year ago)
- Last Synced: 2024-10-31T07:48:21.341Z (3 months ago)
- Language: TypeScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# http-matcher
Simple wrapper for node:http to handle different page requests by using matcher and responder.## Usage
```javascript
const { Server, tryPort } = require('../dist/index');(async ()=>{
if (!(await tryPort(80))) {
throw new Error('Port Occupancy.');
}let server = new Server(80);
server.defaultResponser = (req, res)=>{
// Using node's API
res.statusCode = 200;
res.write(/* HTML */);
res.end();
};server.setHandler(/\/page*/, (req, res)=>{
// Other page's responser
});
})();
```## Build
```sh
npm install
tsc
```