Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/will123195/express-page
Simple webpage controllers for Express.
https://github.com/will123195/express-page
Last synced: 10 days ago
JSON representation
Simple webpage controllers for Express.
- Host: GitHub
- URL: https://github.com/will123195/express-page
- Owner: will123195
- License: mit
- Created: 2014-11-01T20:48:41.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-05T19:08:55.000Z (almost 10 years ago)
- Last Synced: 2024-04-14T07:44:42.611Z (8 months ago)
- Language: JavaScript
- Size: 160 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-page
Simple webpage controllers for Express.
Provides a `Page` object context for your controller with the
following properties:- `this.req`
- `this.res`
- `this.accessDenied()`
- `this.css[]`
- `this.js[]`
- `this.notFound()`
- `this.params`
- `this.redirect()`
- `this.render()`
- `this.setView()`
- `this.setLayout()`
- `this.templates`### Install
```
npm install express-page
```### Basic example
```js
var express = require('express')
var Page = require('express-page')
var app = express()
var db = {
count: 0
}
var controller = function() {
this.db.count++
this.res.send('Count is ' + this.db.count)
}app.get('/example', function(req, res) {
var page = Page(controller, {
db: db
}, req, res)
page.run()
})
```### Dynamic routing based on file scan
```js
var express = require('express')
var scan = require('sugar-glob')
var Page = require('express-page')
var app = express()scan({
dir: './pages'
})
.file('*index.js', function(file) {
var uri = '/' + file.dir
app.get(uri, function(req, res) {
var controller = require(file.filename)
var page = Page(controller, {}, req, res)
page.run()
})
})```