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

autostrada

v1.4.2

Published

Auto routes the content of a www directory. You can add a filter to have custom URLs.

Downloads

8

Readme

Autostrada

Autostrada uses Express to auto route the content of a www directory. You can also setup a custom URL for each file.

Installation

$ npm install autostrada

Features

  • All the changes inside the www directory (files added, removed, moved, renamed, modified) are immediately taked into account.
  • The files can be filtered to route only those that you want.
  • You can use a custom URL for each specific file.

Quick Start

Firstly, you must have a www directory at the root of your project. Let use the following example:

your project
├─ main.js
├─ node_modules
│  └─ ...
├─ package-lock.json
├─ package.json
└─ www
   ├─ index.html
   ├─ a-folder
   │  ├─ index.html
   │  └─ page.html
   └─ config.json

Now, you can auto route the www directory by doing:

const app = require('express')();
const autostrada = require('autostrada')();

app.use(autostrada);
app.listen(80);

result:

| file path | URL | |----------------------|--------------------------------------| | /index.html | http://localhost/index.html | | /a-folder/index.html | http://localhost/a-folder/index.html | | /a-folder/page.html | http://localhost/a-folder/page.html | | /config.json | http://localhost/config.json |

Options

| option | default value | |----------------------|--------------------| | wwwDirectory | __dirname + '/www' | | indexableFilesFilter | (path) => true | | fromPathToUrl | (path) => path |

wwwDirectory

You can choose another directory name than 'www' by providing its absolute path. Example:

const autostrada = require('autostrada')({
	wwwDirectory: __dirname + '/www2'
});

indexableFilesFilter

You can choose the files that will be routed by providing a filter. Example:

const autostrada = require('autostrada')({
	indexableFilesFilter: (path) => path !== '/config.json'
});

result (the 'config.json' file is missing):

| file path | URL | |----------------------|--------------------------------------| | /index.html | http://localhost/index.html | | /a-folder/index.html | http://localhost/a-folder/index.html | | /a-folder/page.html | http://localhost/a-folder/page.html |

fromPathToUrl

A function that associates one or many URLs at a file path. Thus, this function retrieves respectively a string or a string array. In the case where it retrieves a string array, the first one is the main URL and the others will redirect to it.

For example, if you want to get rid of the '.html' extensions and to have all the 'index.html' routed to their folder root, you can do this:

const autostrada = require('autostrada')({
	fromPathToUrl: (path) => {
		// '/xxx/yyy/index.html' => ['/xxx/yyy/', '/xxx/yyy']
		if (path.match(/^((.*)\/)index\.html$/)) return [RegExp.$1, RegExp.$2];
		
		// '/xxx/yyy/zzz.html' => '/xxx/yyy/zzz'
		if (path.match(/^(.*)\.html$/)) return RegExp.$1;
		
		// no mofification
		return path;
	}
});

result:

| file path | URL | |----------------------|--------------------------------| | /index.html | http://localhost/ | | /a-folder/index.html | http://localhost/a-folder/ | | /a-folder/page.html | http://localhost/a-folder/page | | /config.json | http://localhost/config.json |

Also, http://localhost will redirect to http://localhost/ and http://localhost/a-folder will redirect to http://localhost/a-folder/.

Last Chance

Autostrada features a function called lastChance:

const app = require('express')();
const autostrada = require('autostrada')();

app.use(autostrada);
// your other routes here
// THEN lastChance:
app.use(autostrada.lastChance(150));
app.listen(80);

Normally, if no route is found, Autostrada just calls next(). With lastChance, Autostrada keeps the request during a given amount of time, here 150ms. If during this period a file corresponding to the request is added to the www directory, the request will be answered. Otherwise, next() is called at the end of the period.

Keep in mind that if no file is found, Autostrada will wait the given amount of time before calling next(). This is a blocking operation.

Author

Clément Saccoccio

Sources

https://gitlab.com/Cl00e9ment/autostrada

Licence

GPL-3.0-or-later