From 16b0fd31c041a54d091161ee67b4ea38958eb203 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 23 Mar 2020 16:07:01 +0100 Subject: [PATCH] documentation --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ src/index.mjs | 10 ++++++---- src/router.mjs | 2 +- 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f9e55bc --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# flummpress + +## Usage Example +```javascript +import path from "path"; +import flummpress, { router, views } from "flummpress"; + +(async () => { + const port = 8080; + (await new flummpress()) + .listen(port) + .on("listening", () => { + console.log(`flummpress is listening on port ${port}`); + + // new route GET + router.get(/^\/$/, (req, res) => { + res.reply({ + body: "hello world!" + }); + }); + + // new route POST + router.post(/^\/$/, async (req, res) => { + const postdata = await req.post; + console.log(postdata); + res.reply({ + body: "hello post!" + }); + }); + + // public folder + router.static({ + dir: path.resolve() + "/public", + route: /^\/public/ + }); + }); +})(); +``` + +## documentation + +coming soon \ No newline at end of file diff --git a/src/index.mjs b/src/index.mjs index c341b65..30f81a4 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -9,12 +9,14 @@ import views from "./views.mjs"; export default class flummpress { constructor(opts) { this.opts = { ...{ - views: path.resolve() + "/src/views", - routes: path.resolve() + "/src/routes" + views: null, + routes: null }, ...opts }; return (async () => { - await router.loadRoutes(this.opts.routes); - await views.loadViews(this.opts.views); + if(this.opts.routes) + await router.loadRoutes(this.opts.routes); + if(this.opts.views) + await views.loadViews(this.opts.views); return this; })(); } diff --git a/src/router.mjs b/src/router.mjs index 26bf54f..713ef7f 100644 --- a/src/router.mjs +++ b/src/router.mjs @@ -23,7 +23,7 @@ export default new class { post() { this.route("POST", arguments); } - async static(dir = path.resolve() + "/public", route = /^\/s/) { + async static({ dir = path.resolve() + "/public", route = /^\/public/ }) { if(!this.#mimes) { this.#mimes = new Map(); (await fs.readFile("/etc/mime.types", "utf-8"))