Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brechtcs/routesfile

Parse ROUTES file for static sites
https://github.com/brechtcs/routesfile

Last synced: about 10 hours ago
JSON representation

Parse ROUTES file for static sites

Awesome Lists containing this project

README

        

# routesfile

Parse ROUTES file for static sites

## Install

`npm install routesfile`

## Usage

```js
var routesfile = require('routesfile')

// async
routesfile.read('./ROUTES', function (err, routes) {
if (err) throw err
// do something with `routes`
})

// sync
var fs = require('fs')

var file = fs.readFileSync('./ROUTES', 'utf-8')
var routes = routesfile.parse(file)
// do something with `routes`
```

## API

### `var routes = routesfile.parse(string)`

Returns a routes objects of the following format:

```js
{
[redirectFromUrl: string]: {
code: [statusCode: number],
target: [redirectToUrl: string]
},
// more routes...
}
```

### `routesfile.read(path, cb)`

Callback with signature `(err, routes)`, with `routes` being the same format as returned by the `parse` method.

## License

Apache-2.0