documentation
This commit is contained in:
parent
ee264a2802
commit
16b0fd31c0
42
README.md
Normal file
42
README.md
Normal 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
|
|
@ -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;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user