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,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;
|
||||
})();
|
||||
|
|
|
@ -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"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user