Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cannot explore a resource if not specify a url/path

  • Loading branch information...
commit 8a2102ece06ff8f8d71eaca37018b8932427d4d4 1 parent 6893527
@lichangwei authored
View
0  .npmignore
No changes.
View
2  lib/extends/Object.js
@@ -1,5 +1,5 @@
-exports.partial = function(obj /*, partial, keys..*/){
+Object.prototype.partial = function(obj /*, partial, keys..*/){
var keys = slice.call(arguments, 1);
// if 2th param is a object, then it's the target.
// or create a new one.
View
2  lib/extends/index.js
@@ -1,4 +1,4 @@
require('./ServerResponse');
-
+require('./Object');
require('./String');
View
13 lib/middleware/router.js
@@ -51,17 +51,16 @@ function load(prefix, root){
restjs.fs.getAllFileNames(root)
.forEach(function(it){
var resource = require(it);
- if( resource.path === null ) return;
-
- var path = resource.path || it.replace(root, '').replace(/\.js$/, '');
- path = prefix + path;
- classify(path, resource, restjs.validate);
+ var url = resource.url || it.replace(root, '').replace(/\.js$/, '');
+ url = path.join(prefix, url);
+ url = url.replace(/\\/g, '/');
+ classify(url, resource, restjs.validate);
+ // resource.del === resource["delete"]
if( !resource["delete"] && resource.del ){
resource["delete"] = resource.del;
}
-
- console.log('collect path: ', path);
+ console.log('collect url: ', url);
});
}
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "restjs",
"description": "A restful-style web framework written with node language",
- "version": "0.0.6",
+ "version": "0.0.7",
"author": {
"name": "Li Chang Wei",
"email": "lichangwei@love.com"
View
4 sample/mock/production.js
@@ -0,0 +1,4 @@
+
+exports.get = function(req, res){
+ res.render({});
+};
View
5 sample/mock/user/index.js
@@ -1,10 +1,10 @@
var users = require('../data').users;
-exports.path = '/user/{id}';
+exports.url = '/user/{id}';
exports.get = function(req, res, next){
- var id = req.params.id;
+ var id = parseInt(req.params.id, 10);
var user = users.filter(function(u){
return u.id === id;
})[0];
@@ -19,6 +19,7 @@ exports.put = function(req, res, next){
var now = + new Date();
var data = req.body;
var user = data.partial('name', 'age', 'title');
+ user.id = users.length;
user.create_dt = now;
user.update_dt = now;
users.push( user );
View
13 sample/public/index.html
@@ -16,17 +16,17 @@
<p>
<label>name: </label>
<input name="name">
- <span>{{error.name}}</span>
+ <span data-value="{{error.name}}"></span>
</p>
<p>
<label>age: </label>
<input name="age" number>
- <span>{{error.age}}</span>
+ <span data-value="{{error.age}}"></span>
</p>
<p>
<label>title: </label>
<input name="title">
- <span>{{error.title}}</span>
+ <span data-value="{{error.title}}"></span>
</p>
<p>
<input type="button" id="submit" value="submit">
@@ -39,14 +39,13 @@
<script src="https://raw.github.com/lichangwei/domtemp/master/text-scanner.js"></script>
-->
<script src="/scripts/libs/amanda.js"></script>
- <script src="http://127.0.0.1/github/domtemp/domtemp.js"></script>
- <script src="http://127.0.0.1/github/domtemp/form-scanner.js"></script>
- <script src="http://127.0.0.1/github/domtemp/text-scanner.js"></script>
+ <script src="http://127.0.0.1/github/domtemp/src/domtemp.js"></script>
+ <script src="http://127.0.0.1/github/domtemp/src/form-scanner.js"></script>
<script src="/validation.js"></script>
<script>
var form = document.getElementById('add_user');
var submit = document.getElementById('submit');
- var template = dt(form).clean();
+ var template = dt(form);
submit.addEventListener('click', function(){
var url = '/user/1';
View
13 sample/test/production.js
@@ -0,0 +1,13 @@
+
+var request = require('supertest')('http://localhost:3000');
+var expect = require('chai').expect;
+
+describe('/production', function(){
+ it('GET', function(done){
+ request.get('/production')
+ .expect(200)
+ .expect('Content-Type', 'text/json')
+ .end(done);
+ });
+
+});
View
50 sample/test/user.js
@@ -0,0 +1,50 @@
+
+var request = require('supertest')('http://localhost:3000');
+var expect = require('chai').expect;
+
+describe('/user/{id}', function(){
+ it('GET', function(done){
+ request.get('/user/0')
+ .expect(200)
+ .expect('Content-Type', 'text/json')
+ .expect('{"code":404,"msg":"Cannot find the user whose id is 0"}')
+ .end(done);
+ });
+
+ it('PUT', function(done){
+ request.put('/user/')
+ .send('name=restjs')
+ .send('age=23')
+ .send('title=fe')
+ .expect(200)
+ .end(done);
+ });
+
+ it('GET', function(done){
+ request.get('/user/0')
+ .expect(200)
+ .expect('Content-Type', 'text/json')
+ .end(function(err, res){
+ it('should return a user after inserted', function(){
+ expect(res.body.code).to.equal(200);
+ });
+ done();
+ });
+ });
+
+ it('POST', function(done){
+ request.post('/user/0')
+ .send('name=restjs')
+ .send('age=25')
+ .send('title=be')
+ .expect(200)
+ .end(done);
+ });
+
+ it('DELETE', function(done){
+ request.del('/user/0')
+ .expect(200)
+ .end(done);
+ });
+
+});
View
2  test/middlerware/cors.js
@@ -0,0 +1,2 @@
+var restjs = require('../../index');
+restjs.cros();
Please sign in to comment.
Something went wrong with that request. Please try again.