documentation

This commit is contained in:
Flummi 2020-03-23 16:07:01 +01:00
parent ee264a2802
commit 16b0fd31c0
3 changed files with 49 additions and 5 deletions

42
README.md Normal file
View File

@ -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

View File

@ -9,12 +9,14 @@ import views from "./views.mjs";
export default class flummpress { export default class flummpress {
constructor(opts) { constructor(opts) {
this.opts = { ...{ this.opts = { ...{
views: path.resolve() + "/src/views", views: null,
routes: path.resolve() + "/src/routes" routes: null
}, ...opts }; }, ...opts };
return (async () => { return (async () => {
await router.loadRoutes(this.opts.routes); if(this.opts.routes)
await views.loadViews(this.opts.views); await router.loadRoutes(this.opts.routes);
if(this.opts.views)
await views.loadViews(this.opts.views);
return this; return this;
})(); })();
} }

View File

@ -23,7 +23,7 @@ export default new class {
post() { post() {
this.route("POST", arguments); this.route("POST", arguments);
} }
async static(dir = path.resolve() + "/public", route = /^\/s/) { async static({ dir = path.resolve() + "/public", route = /^\/public/ }) {
if(!this.#mimes) { if(!this.#mimes) {
this.#mimes = new Map(); this.#mimes = new Map();
(await fs.readFile("/etc/mime.types", "utf-8")) (await fs.readFile("/etc/mime.types", "utf-8"))