Filesystem-based routing for Express.js
A file-based router for Express / Connect
Diretto makes it easy to create
content folders (can be named anything) from to easily serve content with granular control of application behaviour.
It's inspired by files-based CMSs like Stacey, but it uses Node.js and Express.js.
Create a folder in you project, anywhere (project root in this example):
/appDir /projects /project-1 /public style.less index.jade index.yml /some-other-project /public style.less index.jade index.yml /...
The YML may look like this (
url is required):
title: Coke Beatboxdescription: This is a description for the Googleurl: some-cool-projectid:author: Tommaso <email@example.com>date:modified: 2013-03-13published: 2013-02-23published: true
Then you can use it like this:
// Require Direttovar diretto = require'connect-diretto';// Create a new instance pointing to the content foldervar projects = diretto__dirname + '/projects';// Mount the middleware// Note we mount the middleware to respond on /work (this could be// anything or left empty). Watch out for middleware stack order!appuse'/work' projectsapp;// Set it upprojectseachappuseexpressstaticpathjoinconfig__dirname config__filename '/public';appset'views' pathjoinconfig__dirname config__filename;appuselessMW src: pathjoinconfig__dirname config__filename '/public' ;appuseapprouter;;// Add routing// '/' will in fact respond to '/work/some-cool-project'// Diretto adds .diretto to the request object.// Config is a shorthand to the currently matched configprojectseachappget'/'resrender'index.jade' _defaultsreqdirettoconfigextraData: 'extra'moreExtra: 'encore';;;