Based on the expression express.js, I want to let flatiron try a small project. However, there are some minor issues that prevent me from actually getting anywhere.
var flatiron = require('flatiron') , session = require('connect').session , ecstatic = require('ecstatic') , path = require('path') , fs = require('fs') , plates = require('plates') , director = require('director') , winston = require('winston') , union = require('union'); var router = new director.http.Router(); var server = union.createServer({ before: [ ecstatic(__dirname + '/public') ] }); router.get('/', function () { var self = this; fs.readFile('public/layout.html', 'utf-8', function(err, html) { [...] }) }); server.listen(3000, function () { console.log('Application is now started on port 3000'); });
How does routing work with a director? When I leave ecstatic , I can define routes like '/' and it works, but then I don't get static CSS and JS content. With ecstatic / it is replaced with index.html, and ecstatic takes precedence over all defined routes. - This is the same behavior with connect-static. The route (/) is replaced by index.html.
I also tried using a different approach, using middleware to connect, which does not work:
var flatiron = require('flatiron') , connect = require('connect') , path = require('path') , fs = require('fs') , plates = require('plates') , app = flatiron.app; app.use(flatiron.plugins.http); app.use(connect.favicon()); app.use(connect.static(__dirname + '/public')); app.use(connect.directory(__dirname + '/public')); app.use(connect.cookieParser('my secret here')); app.use(connect.session({'secret': 'keyboard cat'})); app.router.get('/', function () { console.log("GET /"); var self = this; fs.readFile('public/layout.html', 'utf-8', function(err, html) { [...] }) }); app.listen(3000, function () { console.log('Application is now started on port 3000'); });
Patrick
source share