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,11 +9,13 @@ 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 () => {
if(this.opts.routes)
await router.loadRoutes(this.opts.routes);
if(this.opts.views)
await views.loadViews(this.opts.views);
return this;
})();

View File

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