forked from GoogleCloudPlatform/nodejs-getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jon Wayne Parrott
committed
Dec 1, 2015
0 parents
commit 20cd0a2
Showing
109 changed files
with
9,072 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"camelcase" : true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"globalstrict": true, | ||
"indent": 2, | ||
"newcap": true, | ||
"maxlen": 80, | ||
"node": true, | ||
"quotmark": "single", | ||
"strict": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "stable" | ||
- "0.12" | ||
- "0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2015, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var express = require('express'); | ||
|
||
var app = express(); | ||
|
||
|
||
// [START hello_world] | ||
// Say hello! | ||
app.get('/', function(req, res) { | ||
res.status(200).send('Hello, world!'); | ||
}); | ||
// [END hello_world] | ||
|
||
|
||
// [START server] | ||
// Start the server | ||
var server = app.listen(process.env.PORT || 8080, function () { | ||
var host = server.address().address; | ||
var port = server.address().port; | ||
|
||
console.log('App listening at http://%s:%s', host, port); | ||
}); | ||
// [END server] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2015, Google, Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# [START runtime] | ||
runtime: nodejs | ||
vm: true | ||
# [END runtime] | ||
|
||
# Temporary setting to keep gcloud from uploading node_modules | ||
skip_files: | ||
- ^node_modules$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "nodejs-getting-started", | ||
"version": "1.0.0", | ||
"description": "End to end sample for running Node.JS applications on Google Cloud Platform", | ||
"repository": "https://github.com/GoogleCloudPlatform/nodejs-getting-started", | ||
"private": true, | ||
"scripts": { | ||
"start": "node app.js", | ||
"monitor": "nodemon app.js", | ||
"deploy": "gcloud preview app deploy app.yaml", | ||
"lint": "jshint --exclude-path=.gitignore .", | ||
"test": "npm run lint" | ||
}, | ||
"author": "Google Inc.", | ||
"contributors": [ | ||
{ | ||
"name": "Jon Wayne Parrott", | ||
"email": "jonwayne@google.com" | ||
}, | ||
{ | ||
"name": "Jonathan Simon", | ||
"email": "jbsimon@google.com" | ||
}, | ||
{ | ||
"name": "Jason Dobry", | ||
"email": "jdobry@google.com" | ||
} | ||
], | ||
"license": "Apache Version 2.0", | ||
"dependencies": { | ||
"express": "^4.13.3" | ||
}, | ||
"devDependencies": { | ||
"jshint": "^2.8.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.12.7" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2015, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var path = require('path'); | ||
var express = require('express'); | ||
var config = require('./config'); | ||
|
||
var app = express(); | ||
|
||
app.disable('etag'); | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
app.set('trust proxy', true); | ||
|
||
|
||
// Books | ||
var model = require('./books/model-' + config.dataBackend)(config); | ||
app.use('/books', require('./books/crud')(model)); | ||
app.use('/api/books', require('./books/api')(model)); | ||
|
||
|
||
// Redirect root to /books | ||
app.get('/', function(req, res) { | ||
res.redirect('/books'); | ||
}); | ||
|
||
|
||
// Basic error handler | ||
app.use(function(err, req, res, next) { | ||
/* jshint unused:false */ | ||
console.error(err.stack); | ||
res.status(500).send('Something broke!'); | ||
}); | ||
|
||
|
||
// Start the server | ||
var server = app.listen(config.port, function () { | ||
var host = server.address().address; | ||
var port = server.address().port; | ||
|
||
console.log('App listening at http://%s:%s', host, port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2015, Google, Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
runtime: nodejs | ||
vm: true | ||
|
||
# Temporary setting to keep gcloud from uploading node_modules | ||
skip_files: | ||
- ^node_modules$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2015, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var express = require('express'); | ||
var bodyParser = require('body-parser'); | ||
|
||
|
||
module.exports = function(model) { | ||
|
||
var router = express.Router(); | ||
|
||
router.use(bodyParser.json()); | ||
|
||
|
||
function handleRpcError(err, res) { | ||
if (err.code === 404) { return res.status(404); } | ||
res.status(500).json({ | ||
message: err.message, | ||
internalCode: err.code | ||
}); | ||
} | ||
|
||
|
||
router.get('/', function list(req, res) { | ||
model.list(10, req.query.pageToken, | ||
function(err, entities, cursor) { | ||
if (err) { return handleRpcError(err, res); } | ||
res.json({ | ||
items: entities, | ||
nextPageToken: cursor | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
router.post('/', function insert(req, res) { | ||
model.create(req.body, function(err, entity) { | ||
if (err) { return handleRpcError(err, res); } | ||
res.json(entity); | ||
}); | ||
}); | ||
|
||
|
||
router.get('/:book(\\d+)', function get(req, res) { | ||
model.read(req.params.book, function(err, entity) { | ||
if (err) { return handleRpcError(err, res); } | ||
res.json(entity); | ||
}); | ||
}); | ||
|
||
|
||
router.put('/:book(\\d+)', function update(req, res) { | ||
model.update(req.params.book, req.body, function(err, entity) { | ||
if (err) { return handleRpcError(err, res); } | ||
res.json(entity); | ||
}); | ||
}); | ||
|
||
|
||
router.delete('/:book(\\d+)', function _delete(req, res) { | ||
model.delete(req.params.book, function(err) { | ||
if (err) { return handleRpcError(err, res); } | ||
res.status(200).send('OK'); | ||
}); | ||
}); | ||
|
||
return router; | ||
|
||
}; |
Oops, something went wrong.