UNPKG

griffinwebserver_v2

Version:

Basic webserver library to serve files in a folder. But can also have specific paths like /api/ that is handled by custom function.

16 lines (12 loc) 454 B
const Webserver = require('./webserver'); const webserver = new Webserver('www/', 8080); webserver.start(); function apiFunction(req, res) { const baseUrl = 'http://' + req.headers.host + '/'; const parsedUrl = new URL(req.url, baseUrl); res.end(parsedUrl.pathname.split('/')[2]); } webserver.addHandler('/api/', apiFunction); /* if you point your browser towards http://127.0.0.1:8080/api/kaka you will be served with a page called kaka */