-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial import #1
Changes from 1 commit
16ff57a
af10f62
55ea0fb
256e549
c748cfc
e70fbbe
cb6bbac
cfef743
4ed8215
555c092
a1edb02
6f3a685
66d5c52
daf80f2
6484462
21f5849
95a70eb
4fb8c26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# How to become a contributor and submit your own code | ||
|
||
## Contributor License Agreements | ||
|
||
We'd love to accept your patches! Before we can take them, we have to jump a couple of legal hurdles. | ||
|
||
Please fill out either the individual or corporate Contributor License Agreement (CLA). | ||
|
||
* If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). | ||
* If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). | ||
|
||
Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests. | ||
|
||
## Contributing A Patch | ||
|
||
1. Submit an issue describing your proposed change to the repo in question. | ||
1. The repo owner will respond to your issue promptly. | ||
1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). | ||
1. Fork the desired repo, develop and test your code changes. | ||
1. Submit a pull request. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM google/nodejs-runtime |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
application: gcloud-node-todos | ||
module: default | ||
version: 1 | ||
runtime: custom | ||
api_version: 1 | ||
vm: true | ||
manual_scaling: | ||
instances: 1 | ||
|
||
handlers: | ||
- url: .* | ||
script: dynamic |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "todomvm-nodejs", | ||
"description": "todomvc sample for gcloud-node", | ||
"version": "0.0.1", | ||
"license": "Apache 2.0", | ||
"dependencies": { | ||
"express": "^4.5.1", | ||
"body-parser": "^1.4.3", | ||
"gcloud": "^0.4.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
var express = require('express'), | ||
bodyParser = require('body-parser'), | ||
app = express(); | ||
|
||
var gcloud = require('gcloud'), | ||
datastore = gcloud.datastore; | ||
|
||
var ds = new datastore.Dataset({ | ||
projectId: process.env.GAE_LONG_APP_ID || process.env.DATASET_ID, | ||
keyFilename: 'key.json' | ||
}); | ||
|
||
app.use(bodyParser.json()); | ||
|
||
var todoListName = 'default-list'; | ||
|
||
app.get('/', function(req, res) { | ||
res.send(200, 'hello world'); | ||
}); | ||
|
||
app.get('/todos', function(req, res) { | ||
var q = ds.createQuery('Todo') | ||
.hasAncestor(ds.key('TodoList', todoListName)); | ||
ds.runQuery(q, function(err, items) { | ||
if (err) { | ||
console.error(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing comma after console.error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean semicolon? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean semicolon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
res.status(500).send(err.message); | ||
return; | ||
} | ||
res.json(items.map(function(obj, i) { | ||
obj.data.id = obj.key.path_.pop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add some pseudo getters for IDs and names to avoid this. |
||
return obj.data; | ||
})); | ||
}); | ||
}); | ||
|
||
app.get('/todos/:id', function(req, res) { | ||
var id = req.param('id'); | ||
ds.get(ds.key('TodoList', todoListName, 'Todo', id), function(err, obj) { | ||
if (err) { | ||
console.error(err) | ||
res.status(500).send(err.message); | ||
return; | ||
} | ||
if (!obj) { | ||
return res.send(404); | ||
} | ||
obj.data.id = obj.key.path_.pop(); | ||
res.json(obj.data); | ||
}); | ||
}); | ||
|
||
app.post('/todos', function(req, res) { | ||
var todo = req.body; | ||
ds.save({ | ||
key: ds.key('TodoList', todoListName, 'Todo'), | ||
data: todo | ||
}, function(err, key) { | ||
if (err) { | ||
console.error(err) | ||
res.status(500).send(err.message); | ||
return; | ||
} | ||
todo.id = key.path_.pop(); | ||
res.json(todo); | ||
}); | ||
}); | ||
|
||
app.put('/todos/:id', function(req, res) { | ||
var id = req.param('id'); | ||
var todo = req.body; | ||
ds.save({ | ||
key: ds.key('TodoList', todoListName, 'Todo', id), | ||
data: todo | ||
}, function(err, key) { | ||
if (err) { | ||
console.error(err) | ||
res.status(500).send(err.message); | ||
return; | ||
} | ||
todo.id = id; | ||
res.json(todo); | ||
}); | ||
}); | ||
|
||
app.delete('/todos/:id', function(req, res) { | ||
var id = req.param('id'); | ||
ds.delete(ds.key('TodoList', todoListName, 'Todo', id), function(err) { | ||
if (err) { | ||
console.error(err) | ||
res.status(500).send(err.message); | ||
return; | ||
} | ||
res.send(200); | ||
}); | ||
}); | ||
|
||
app.delete('/todos', function(req, res) { | ||
ds.runInTransaction(function(t, done) { | ||
var q = ds.createQuery('Todo') | ||
.hasAncestor(ds.key('TodoList', todoListName)) | ||
.filter('completed =', true); | ||
t.runQuery(q, function(err, items) { | ||
if (err) { | ||
t.rollback(done); | ||
console.error(err) | ||
res.status(500).send(err.message); | ||
return; | ||
} | ||
var keys = items.map(function(obj) { | ||
return obj.key; | ||
}); | ||
t.delete(keys, function(err) { | ||
if (err) { | ||
t.rollback(done); | ||
console.error(err) | ||
res.status(500).send(err.message); | ||
return; | ||
} | ||
done(); | ||
res.send(200); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
app.listen(8080); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to do the following once googleapis/google-cloud-node#154 is merged.