Skip to content

Commit 1b4867b

Browse files
committed
Merge pull request #6 from GoogleCloudPlatform/pr/5
pr/5
2 parents 92e3623 + c0c1f27 commit 1b4867b

212 files changed

Lines changed: 24525 additions & 6 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.jshintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
appengine/kraken/public/components/**
2+
appengine/sails/config/**
3+
appengine/sails/tasks/**
4+
appengine/sails/assets/**
5+
node_modules

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ install:
4040
#Use '-q' to disable interactive prompts
4141

4242
script:
43-
- jshint --exclude-path=.gitignore .
43+
- jshint --exclude-path=.jshintignore .

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1-
## Google Cloud Platform NodeJS Samples
1+
# Google Cloud Platform NodeJS Samples
22

3-
This repository holds the samples used in the nodejs documentation on [cloud.google.com](https://cloud.google.com).
3+
This repository holds the samples used in the nodejs documentation on [cloud.google.com/nodejs](https://cloud.google.com/nodejs).
44

55
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/nodejs-docs-samples.svg)](https://travis-ci.org/GoogleCloudPlatform/nodejs-docs-samples)
66

7-
See our other [Google Cloud Platform github
8-
repos](https://github.com/GoogleCloudPlatform) for sample applications and
9-
scaffolding for other frameworks and use cases.
7+
## Google App Engine
8+
9+
This is a collection of samples and instructions to run common nodejs frameworks and applications on [Google App Engine](http://cloud.google.com/nodejs).
10+
11+
### Frameworks
12+
13+
- [Express](appengine/express/)
14+
- [Hapi](appengine/hapi/)
15+
- [Loopback](appengine/loopback/)
16+
- [Sails](appengine/sails/)
17+
- [Koa](appengine/koa/)
18+
- [Kraken](appengine/kraken/)
19+
- [Restify](appengine/restify/)
20+
- [Geddy](appengine/geddy/)
21+
22+
### Services
23+
24+
- [Redis](appengine/redis/)
25+
26+
### Tools
27+
28+
- [Grunt](appengine/grunt/)
29+
30+
### More information
31+
32+
- [Getting started with nodejs on Google Cloud](http://cloud.google.com/nodejs/)
33+
- See our other [Google Cloud Platform github repos](https://github.com/GoogleCloudPlatform) for sample applications and scaffolding for other frameworks and use cases.
34+
- [Using the `gcloud` npm module](https://googlecloudplatform.github.io/gcloud-node/#/)
35+
- [Logging to Google Cloud with Winston](https://github.com/GoogleCloudPlatform/winston-gae)
1036

1137
## Contributing changes
1238

appengine/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# nodejs -> Google App Engine
2+
3+
This is a collection of samples and instructions to run common nodejs frameworks and applications on [Google App Engine](http://cloud.google.com/nodejs).
4+
5+
## Frameworks
6+
7+
- [Express](express/)
8+
- [Hapi](hapi/)
9+
- [Loopback](/loopback)
10+
- [Sails](sails/)
11+
- [Koa](koa/)
12+
- [Kraken](kraken/)
13+
- [Restify](restify/)
14+
- [Geddy](geddy/)
15+
16+
## Services
17+
18+
- [Redis](redis/)
19+
20+
## Tools
21+
22+
- [Grunt](grunt/)
23+
24+
## More info
25+
26+
- [Getting started with nodejs on Google Cloud](http://cloud.google.com/nodejs/)
27+
- [Using the `gcloud` npm module](https://googlecloudplatform.github.io/gcloud-node/#/)
28+
- [Logging to Google Cloud with Winston](https://github.com/GoogleCloudPlatform/winston-gae)
29+

appengine/express/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Express -> Google App Engine
2+
3+
This is a simple guide to running [expressjs](http://expressjs.com/) on Google App Engine.
4+
5+
1. [Create a new Express app](http://expressjs.com/starter/generator.html)
6+
7+
2. Create an `app.yaml` in the root of your application with the following contents:
8+
9+
```yaml
10+
runtime: nodejs
11+
vm: true
12+
env_variables:
13+
PORT: 8080
14+
```
15+
16+
3. Deploy your app. For convenience, you can use an npm script to run the command. Modify your `package.json` to include:
17+
18+
```js
19+
"scripts": {
20+
"start": "node ./bin/www",
21+
"deploy": "gcloud preview app deploy app.yaml --set-default --project [project id]"
22+
}
23+
```
24+
25+
At the terminal you can now run `npm run deploy` to deploy your application.

appengine/express/app.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2015, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
var express = require('express');
17+
var path = require('path');
18+
var logger = require('morgan');
19+
var cookieParser = require('cookie-parser');
20+
var bodyParser = require('body-parser');
21+
22+
var routes = require('./routes/index');
23+
var users = require('./routes/users');
24+
25+
var app = express();
26+
27+
// view engine setup
28+
app.set('views', path.join(__dirname, 'views'));
29+
app.set('view engine', 'jade');
30+
31+
app.use(logger('dev'));
32+
app.use(bodyParser.json());
33+
app.use(bodyParser.urlencoded({ extended: false }));
34+
app.use(cookieParser());
35+
app.use(express.static(path.join(__dirname, 'public')));
36+
37+
app.use('/', routes);
38+
app.use('/users', users);
39+
40+
// catch 404 and forward to error handler
41+
app.use(function(req, res, next) {
42+
var err = new Error('Not Found');
43+
err.status = 404;
44+
next(err);
45+
});
46+
47+
// error handlers
48+
49+
// development error handler
50+
// will print stacktrace
51+
if (app.get('env') === 'development') {
52+
app.use(function(err, req, res) {
53+
res.status(err.status || 500);
54+
res.render('error', {
55+
message: err.message,
56+
error: err
57+
});
58+
});
59+
}
60+
61+
// production error handler
62+
// no stacktraces leaked to user
63+
app.use(function(err, req, res) {
64+
res.status(err.status || 500);
65+
res.render('error', {
66+
message: err.message,
67+
error: {}
68+
});
69+
});
70+
71+
72+
module.exports = app;

appengine/express/app.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2015, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
runtime: nodejs
15+
api_version: 1
16+
vm: true
17+
env_variables:
18+
PORT: 8080

appengine/express/bin/www

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
/**
6+
* Module dependencies.
7+
*/
8+
9+
var app = require('../app');
10+
var debug = require('debug')('express:server');
11+
var http = require('http');
12+
13+
/**
14+
* Get port from environment and store in Express.
15+
*/
16+
17+
var port = normalizePort(process.env.PORT || '3000');
18+
app.set('port', port);
19+
20+
/**
21+
* Create HTTP server.
22+
*/
23+
24+
var server = http.createServer(app);
25+
26+
/**
27+
* Listen on provided port, on all network interfaces.
28+
*/
29+
30+
server.listen(port);
31+
server.on('error', onError);
32+
server.on('listening', onListening);
33+
34+
/**
35+
* Normalize a port into a number, string, or false.
36+
*/
37+
38+
function normalizePort(val) {
39+
var port = parseInt(val, 10);
40+
41+
if (isNaN(port)) {
42+
// named pipe
43+
return val;
44+
}
45+
46+
if (port >= 0) {
47+
// port number
48+
return port;
49+
}
50+
51+
return false;
52+
}
53+
54+
/**
55+
* Event listener for HTTP server "error" event.
56+
*/
57+
58+
function onError(error) {
59+
if (error.syscall !== 'listen') {
60+
throw error;
61+
}
62+
63+
var bind = typeof port === 'string'
64+
? 'Pipe ' + port
65+
: 'Port ' + port;
66+
67+
// handle specific listen errors with friendly messages
68+
switch (error.code) {
69+
case 'EACCES':
70+
console.error(bind + ' requires elevated privileges');
71+
process.exit(1);
72+
break;
73+
case 'EADDRINUSE':
74+
console.error(bind + ' is already in use');
75+
process.exit(1);
76+
break;
77+
default:
78+
throw error;
79+
}
80+
}
81+
82+
/**
83+
* Event listener for HTTP server "listening" event.
84+
*/
85+
86+
function onListening() {
87+
var addr = server.address();
88+
var bind = typeof addr === 'string'
89+
? 'pipe ' + addr
90+
: 'port ' + addr.port;
91+
debug('Listening on ' + bind);
92+
}

appengine/express/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "express",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./bin/www",
7+
"deploy": "gcloud preview app deploy app.yaml --set-default --project express-demo"
8+
},
9+
"dependencies": {
10+
"body-parser": "~1.12.4",
11+
"cookie-parser": "~1.3.5",
12+
"debug": "~2.2.0",
13+
"express": "~4.12.4",
14+
"jade": "~1.9.2",
15+
"morgan": "~1.5.3",
16+
"serve-favicon": "~2.2.1"
17+
}
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** Copyright 2015, Google, Inc.
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
body {
15+
padding: 50px;
16+
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
17+
}
18+
19+
a {
20+
color: #00B7FF;
21+
}

0 commit comments

Comments
 (0)