1
0
Fork 0
mirror of https://github.com/sbrl/powahroot.git synced 2024-12-27 13:04:57 +00:00
Find a file
dependabot[bot] 06ac0d999a
Bump json5 and postcss-modules
Bumps [json5](https://github.com/json5/json5) and [postcss-modules](https://github.com/css-modules/postcss-modules). These dependencies needed to be updated together.

Updates `json5` from 2.2.0 to 2.2.3
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v2.2.0...v2.2.3)

Updates `postcss-modules` from 4.1.3 to 4.3.1
- [Release notes](https://github.com/css-modules/postcss-modules/releases)
- [Changelog](https://github.com/madyankin/postcss-modules/blob/master/CHANGELOG.md)
- [Commits](https://github.com/css-modules/postcss-modules/compare/v4.1.3...v4.3.1)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
- dependency-name: postcss-modules
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-02 08:27:45 +00:00
Client Fix resolution logic & tree-shaking 2019-04-28 21:19:30 +01:00
examples Add parse post data middleware example 2020-01-13 00:12:47 +00:00
lantern-build-engine@617fcdb5b9 Start setting up for CI 2019-04-27 18:02:01 +01:00
Server fixup 2022-02-24 01:25:29 +00:00
Shared Use default exports & imports to try to avoid tree-shaking issues 2019-04-28 20:45:51 +01:00
.gitignore Start setting up for CI 2019-04-27 18:02:01 +01:00
.gitmodules Start setting up for CI 2019-04-27 18:02:01 +01:00
.npmignore Add parse post data middleware example 2020-01-13 00:12:47 +00:00
.tern-project Import from Nibriboard-Panel 2019-04-26 23:35:10 +01:00
build build: fix shellcheck errors 2022-05-01 16:38:38 +01:00
CHANGELOG.md Update changelog 2022-05-01 15:57:43 +01:00
Client.mjs Fix resolution logic & tree-shaking 2019-04-28 21:19:30 +01:00
docs.css Change placeholder text colour 2019-04-28 16:12:31 +01:00
FUNDING.yml Add FUNDING.yml 2020-05-25 15:14:08 +01:00
index.mjs Add logo & licence 2019-04-26 23:56:29 +01:00
LICENSE Initial commit 2019-04-26 23:52:55 +01:00
logo-large.png Fix resolution logic & tree-shaking 2019-04-28 21:19:30 +01:00
logo.piskel Add logo & licence 2019-04-26 23:56:29 +01:00
logo.png Fix resolution logic & tree-shaking 2019-04-28 21:19:30 +01:00
package-lock.json Bump json5 and postcss-modules 2023-01-02 08:27:45 +00:00
package.json 1.2.6 2022-05-01 15:58:00 +01:00
README.md Add changelog, update dependencies 2022-05-01 15:47:13 +01:00
Server.mjs Fix resolution logic & tree-shaking 2019-04-28 21:19:30 +01:00

powahroot

Client and server-side routing micro frameworks

Powahroot is a pair of micro routing frameworks, presented as an ES6 module:

  • The first is for client-side single-page web applications
  • The other is for handling server-side Node.js requests

It's based on rill (see the npm package bearing the name), but stripped down and simplified.

Getting Started

Install powahroot as a dependency with npm:

npm install --save powahroot

If your build process supports tree-shaking, only the router(s?) you need will be included in the final output of your build - as powahroot uses ES6 modules.

Usage

Paths

Powahroot supports multiple syntax bells and whistles when defining routes. These are documented below:

Syntax Meaning
/index.html Regular route. Matches exactly what it says on the tin.
* Special key(word?) that matches any route. Must be present on its own without any other characters.
/add/vegetable/:name/:weight Parameters. Match values an pull them into an object automatically. Does not like forward slashes in parameter values.
/images/::path Parameter values with forward slashes. If you want to use parameters, but need values to be able to contain forward slashes /, this is for you. Don't forget you can mix-and-match this with the previous example!

Client

Initialise a new router like this:

import ClientRouter from 'powahroot/Client.mjs';

// ....

const router = new ClientRouter({
	// Options object. Default settings:
	verbose: false, // Whether to be verbose in console.log() messages
	listen_pushstate: true, // Whether to react to browser pushstate events (excluding those generated by powahroot itself, because that would cause an infinite loop :P)
});

// Add a page
router.add_page("/add/vegetable/:name/:weight", (params) => {
    console.log(`We added a ${params.name} with a weight of ${params.weight}g.`);
});

// Explicitly navigate to a page:
router.navigate("/add/carrot/frederick/10001");

Server

The server router works slightly differently, to account for the different environment it's designed for. Here's how to use it:

import ServerRouter from 'powahroot/Server.mjs';

// ....

const router = new ServerRouter();
// Logging middle ware
router.on_all(async (context, next) => {
    console.debug(context.url);
    await next();
});
// Regular handlere
router.get("/files/::filepath", (context, _next) => context.send.plain(200, `You requested ${context.params.filepath}`));
// .....

// Later, when you've got a request / response pair to handle:
await router.handle(request, response);

The context argument there is of type RouterContext. Check out the API reference (link below) to learn about the other useful properties it has.

Reference

API docs are generated automatically. View them here:

https://starbeamrainbowlabs.com/code/powahroot/docs/

It contains full documentation on how to use everything, along with code examples to help you get started.

Contributing

Contributions are welcome! Simply fork this repository, make your changes, and submit a Pull Request (issues are welcome too!).

All contributions must be declared to have the Mozilla Public License 2.0 (the same license that this repository is under).

Licence

Everything in this repository except the logo is licenced under the _Mozilla Public License 2.0.

The logo itself is © Copyright Starbeamrainbowlabs 2019. All rights reserved - though you may use it when linking to this project (or to advertise usage in a 'powered by' logo).