npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pinecone-router-middleware-render

v0.0.3

Published

Turbolinks-like functionality for Pinecone Router.

Downloads

12

Readme

Display Server-Rendered Pages with Pinecone Router

GitHub tag (latest by date) npm bundle size Downloads from Jsdelivr Github Downloads from Jsdelivr NPM npm Changelog

A middleware for Pinecone Router that add Turbolinks-like functionality with extra features.

About

A middleware that adds Turbolinks-like functionality for Pinecone Router, while still allowing you to handle routes!

Development version, watch for v1.0 :)

Features:

  • No server co-operation needed! serve regular html files as normally done.
  • Allow route checking before displaying pages! can be used for client-side authorization etc.
  • Preload pages when hovering over links!

Installation

CDN

Include the following <script> tag in the <head> of your document, before Pinecone Router:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js"></script>

ES6 Module:

import 'https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js';

NPM

npm install pinecone-router-middleware-render
// load this middleware
import 'pinecone-router-middleware-render';
// then load pinecone router
import 'pinecone-router';

Important: This must be added before loading Pinecone Router.

Usage

  1. Enable render middleware in the router Settings:
function router() {
	return {
		settings: {
			middlewares: {
				render: {
					enable: true;
				}
			}
		}
	}
<div x-data="router()" x-router></div>

By default this will fetch the whole page and replaces the <body> content. To use another element instead, set its selector in settings.

Settings

render: {
	enable: true,
	basePath: '/',
	selector: '#app',
}

Handling routes while using render

While optional, you can also handle routes while all pages render normally!

<div x-data="router()" x-router>
	<template x-route="/hello/:name" x-handler="hello"></template>
</div>

Note: The routes will be handled before the page is rendered.

Authorization

If you'd like to make checks before actually displaying a page, using authentication/authorization etc, you can make your checks in the handler. Then within the handler, if you need to redirect the user to another page simply return context.redirect('/another/page') this way it'll prevent the page from rendering and go to the other page directly.

Example:

In this example the user will only be allowed to edit their own profile

<div x-data="router()" x-router>
...
<template
	x-route="/profile/:username/edit"
	x-handler="editProfile"
></template>
...

The handler: (auth is a placeholder name, replace it with your own auth provider methods)

editProfile(context) {
	if (context.params.username != auth.username) {
		return context.redirect('/unauthorized');
	}
}

Advanced

Notfound and specifying routes

By default, 404 pages are left to the server to handle. However, if you'd like to specify the routes allowed, you can do it like this:

<div x-data="router()" x-router>
	<template x-route="/"></template>
	<template x-route="/hello/:name"></template>
	<template x-route="notfound" x-handler="notfound"></template>
</div>

As you see, the handler is optional on routes as the page will be rendered regardless, but you can add it if you need it.

Supported versions

| Version | Pinecone Router Versions | | ------- | ------------------------ | | 0.0.3 | 0.3.0 |

Contributing:

Please refer to CONTRIBUTING.md

Versioning

This projects follow the Semantic Versioning guidelines.

License

Copyright (c) 2021 Rafik El Hadi Houari

Licensed under the MIT license, see LICENSE.md for details.