Permalink
Browse files

improved server directory structure

 * modified session ttl handling
  • Loading branch information...
1 parent 1842316 commit 304129f7f92cfd7950cd96e18a8ea0d75c23cee8 Tim Schindler committed Feb 26, 2012
View
@@ -0,0 +1 @@
+node_modules/
View
@@ -13,15 +13,14 @@
## Installation:
- $ git clone git@github.com:zyndiecate/sayndo.git
- $ cd sayndo/
$ npm install
For session support the redis server is required. The redis
client for node gets installed on "npm install", but you have
- to install the redis server by yourself on your mashine.
+ to install the redis server by yourself on your mashine. Linux
+ user do:
@@ -43,7 +42,17 @@
## Configuration:
- See lib/config/config.js. It´s well commented.
+ You have to structure your directories like this:
+
+ app -
+ |- config -
+ | |- config.js
+ | |- app_locals.js
+ |
+ |- node_modules
+
+ For detailed information see example/config/config.js.
+ It´s well commented.
@@ -99,6 +108,8 @@
The session object by default is just an empty object
literal. You can access the current session like that.
+ How to write sessions and their properties, see the
+ lines below.
res.session
@@ -111,27 +122,14 @@
- Session specific messages can be written to the session object.
- Give a user just that session property and the message will be
- available like that. How to write sessions and their properties,
- see the lines below.
-
- res.session.message
-
-
-
- **Note that the session message by default is just displayed
- one time.** To change that just modify the behaviour in the
- lib/app/app_local.js.
-
-
-
Create a new session with the authType "admin" for only
10 minutes. **To create a new valid session you need to define
the "authType" attribute, related to the auth types in your
- config.js.**
+ config.js.** You can set the "time to life" explicity. If it
+ is not provided by you, the "ttl" property of your config file
+ is used. Otherwise the default "ttl" is to 1 year.
- res.session.write({authType: 'admin', user: 'John'}, 10);
+ res.session.write({authType: 'admin', user: 'John', ttl: 10} [, cb]);
@@ -194,7 +192,7 @@
To redirect clients just do that:
- res.redirect('/redirect');
+ res.view.redirect('/redirect');
@@ -203,6 +201,14 @@
+## Sending Data:
+
+ Just to send Json or string data do:
+
+ res.view.send(stringOrObject);
+
+
+
## Locals:
Locals are placeholder in views to insert data from the
@@ -248,7 +254,7 @@
app.js
app.guest.GET['/'] = function(req, res) {
- res.render('/index.html', {msg: 'hello world'});
+ res.view.render('/index.html', {msg: 'hello world'});
};
@@ -304,7 +310,7 @@
Tests are implemented with https://github.com/cloudhead/vows.
$ sudo npm install vows -g
- $ vows lib/sayndo/tests/* --spec
+ $ vows node_modules/sayndo/test/* --spec
View
@@ -1,11 +0,0 @@
-/*
- *
- * Server site app locals module.
- *
- */
-
-/*
- * Just require the module and export it.
- */
-module.exports = require('../../config/app_locals.js');
-
View
@@ -1,11 +0,0 @@
-/*
- *
- * Server site config module.
- *
- */
-
-/*
- * Just require the module and export it.
- */
-module.exports = require('../../config/config.js');
-
View
@@ -0,0 +1,11 @@
+/*
+ *
+ * Server site app locals.
+ *
+ */
+
+/*
+ * Just require the module and export it.
+ */
+module.exports = require('../../../config/app_locals.js');
+
View
@@ -0,0 +1,11 @@
+/*
+ *
+ * Server site config.
+ *
+ */
+
+/*
+ * Just require the module and export it.
+ */
+module.exports = require('../../../config/config.js');
+
@@ -9,37 +9,11 @@
*/
var appLocals = {
/*
- * Set the app title globaly.
*
- * @return string, of the app name.
*/
- title: function() {
+ title: function(req, res) {
return 'Sayndo';
- },
-
- /*
- * Get the session message html for each view.
- *
- * @param req, nodes request object.
- * @param res, nodes response object.
- *
- * @return concatinated html string containing the session message.
- */
- message: function(req, res) {
- var message = '<div class="message">'
- , sessionMessage = res.session.message;
-
- if(typeof sessionMessage === 'string'
- && sessionMessage.length != 0) {
- message += sessionMessage;
-
- res.session.update({message: ''});
- }
-
- message += '</div>';
-
- return message;
- },
+ }
};
module.exports = appLocals;
View
@@ -55,6 +55,11 @@ var config = {
dependencies: [],
/*
+ * Session lifetime in minutes.
+ */
+ ttl: 60 * 24 * 365, // 1 year
+
+ /*
* Array of request methods the server have to support.
* This request methods are also supported for the view
* route functions.
@@ -83,7 +88,16 @@ var config = {
* String of random character to create save hashes. The
* security salt is a dependency for the session support.
*/
- securitySalt: '2RFD6jDdrdmpp9790kjIhug76ZG76hoiUkjg',
+ securitySalt: 'jsdhh2hi3d237d89JKH78jhHIPP=00JKJnjn',
+
+ /*
+ *
+ */
+ mysql: {
+ user: 'user',
+ password: 'password',
+ database: 'database'
+ },
/*
* Array containing strings to ignore unwanted files and
View
@@ -1,4 +1,4 @@
/*
* Just require the server.
*/
-module.exports = require('./server.js');
+module.exports = require('./lib/server.js');
@@ -5,7 +5,7 @@ var fs = require('fs')
, path = require('path')
, file = require('./file.js')
, view = require('./view.js')
- , config = require('./config.js')
+ , config = require('../config/config.js')
, layoutPattern = /layout/g;
@@ -59,7 +59,7 @@ var cache = {
view.parseLocals(layoutHtml, {view: viewHtml}, function(html) {
var rawPath = filePath.replace(config.viewPath, '');
- view.cache[rawPath] = viewHtml;
+ view.cache['none' + rawPath] = viewHtml;
view.cache[type + rawPath] = html;
});
});
@@ -59,6 +59,27 @@ var cookie = {
);
}
});
+ },
+
+ /*
+ *
+ */
+ init: function init(req, res, cb) {
+ res.cookie = {};
+
+ res.cookie.read = function(key, cb) {
+ cookie.read(req.headers.cookie, key, cb);
+ };
+
+ res.cookie.write = function(key, value, properties, minutes) {
+ cookie.write(res, key, value, properties, minutes);
+ };
+
+ res.cookie.remove = function(key) {
+ cookie.remove(req.headers.cookie, res, key);
+ };
+
+ cb();
}
};
View
@@ -3,7 +3,7 @@
*/
var fs = require('fs')
, view = require('./view.js')
- , config = require('./config.js');
+ , config = require('../config/config.js');
/*
* File module.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit 304129f

Please sign in to comment.