Skip to content

Commit 29f2d41

Browse files
add appengine samples
1 parent 92e3623 commit 29f2d41

File tree

216 files changed

+32827
-5
lines changed

Some content is hidden

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

216 files changed

+32827
-5
lines changed

README.md

+31-5
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

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
## Libraries
17+
18+
- [socket.io](socketio/)
19+
20+
## Services
21+
22+
- [Redis](redis/)
23+
24+
## Tools
25+
26+
- [Grunt](grunt/)
27+
28+
## More info
29+
30+
- [Getting started with nodejs on Google Cloud](http://cloud.google.com/nodejs/)
31+
- [Using the `gcloud` npm module](https://googlecloudplatform.github.io/gcloud-node/#/)
32+
- [Logging to Google Cloud with Winston](https://github.com/GoogleCloudPlatform/winston-gae)
33+

appengine/express/README.md

+25
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

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var favicon = require('serve-favicon');
4+
var logger = require('morgan');
5+
var cookieParser = require('cookie-parser');
6+
var bodyParser = require('body-parser');
7+
8+
var routes = require('./routes/index');
9+
var users = require('./routes/users');
10+
11+
var app = express();
12+
13+
// view engine setup
14+
app.set('views', path.join(__dirname, 'views'));
15+
app.set('view engine', 'jade');
16+
17+
// uncomment after placing your favicon in /public
18+
//app.use(favicon(__dirname + '/public/favicon.ico'));
19+
app.use(logger('dev'));
20+
app.use(bodyParser.json());
21+
app.use(bodyParser.urlencoded({ extended: false }));
22+
app.use(cookieParser());
23+
app.use(express.static(path.join(__dirname, 'public')));
24+
25+
app.use('/', routes);
26+
app.use('/users', users);
27+
28+
// catch 404 and forward to error handler
29+
app.use(function(req, res, next) {
30+
var err = new Error('Not Found');
31+
err.status = 404;
32+
next(err);
33+
});
34+
35+
// error handlers
36+
37+
// development error handler
38+
// will print stacktrace
39+
if (app.get('env') === 'development') {
40+
app.use(function(err, req, res, next) {
41+
res.status(err.status || 500);
42+
res.render('error', {
43+
message: err.message,
44+
error: err
45+
});
46+
});
47+
}
48+
49+
// production error handler
50+
// no stacktraces leaked to user
51+
app.use(function(err, req, res, next) {
52+
res.status(err.status || 500);
53+
res.render('error', {
54+
message: err.message,
55+
error: {}
56+
});
57+
});
58+
59+
60+
module.exports = app;

appengine/express/app.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
runtime: nodejs
2+
api_version: 1
3+
vm: true
4+
env_variables:
5+
PORT: 8080

appengine/express/bin/www

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

appengine/express/package.json

+18
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
body {
2+
padding: 50px;
3+
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4+
}
5+
6+
a {
7+
color: #00B7FF;
8+
}

appengine/express/routes/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var express = require('express');
2+
var router = express.Router();
3+
4+
/* GET home page. */
5+
router.get('/', function(req, res, next) {
6+
res.render('index', { title: 'Express |2|' });
7+
});
8+
9+
module.exports = router;

appengine/express/routes/users.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var express = require('express');
2+
var router = express.Router();
3+
4+
/* GET users listing. */
5+
router.get('/', function(req, res, next) {
6+
res.send('respond with a resource');
7+
});
8+
9+
module.exports = router;

appengine/express/views/error.jade

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends layout
2+
3+
block content
4+
h1= message
5+
h2= error.status
6+
pre #{error.stack}

appengine/express/views/index.jade

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extends layout
2+
3+
block content
4+
h1= title
5+
p Welcome to #{title}

appengine/express/views/layout.jade

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
doctype html
2+
html
3+
head
4+
title= title
5+
link(rel='stylesheet', href='/stylesheets/style.css')
6+
body
7+
block content

appengine/geddy/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.swp
2+
*.swo
3+
dist
4+
node_modules
5+
*.DS_Store
6+
log/
7+
npm-debug.log
8+
config/secrets.json
9+
public/js/core/models.js
10+
public/js/core/helpers.js

appengine/geddy/Jakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
var t = new jake.TestTask('geddy', function () {
3+
this.testFiles.include('test/*.js');
4+
this.testFiles.include('test/**/*.js');
5+
});
6+

appengine/geddy/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Geddy -> Google App Engine
2+
3+
This is a simple guide to running [geddy](http://geddyjs.org/) on Google App Engine.
4+
5+
1. [Create a new geddy app](http://geddyjs.org/tutorial).
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+
api_version: 1
13+
env_variables:
14+
PORT: 8080
15+
```
16+
17+
3. Create a `server.js` that contains the following code:
18+
19+
```js
20+
var geddy = require('geddy');
21+
22+
geddy.start({
23+
port: process.env.PORT || '3000'
24+
});
25+
```
26+
27+
4. Run `npm install --save geddy`
28+
29+
5. Deploy! For convenience, you can modify your `package.json` to use an npm script for deployment:
30+
31+
```js
32+
"scripts": {
33+
...
34+
"deploy": "gcloud preview app deploy app.yaml --set-default --project [project id]"
35+
}
36+
```
37+
38+
At the terminal you can now run `npm run deploy` to deploy your application.

appengine/geddy/_session_store.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Ln54fnyKo1FzNDpn7DPWhqOclmjjPTbm6K9XyCrSQbny9s1o8EJgLVxCILDEfKK7YUk4mcEcwsQmxyWwJ90ocQGEYB21aYTrl6qlljiPidZxikwV8Kt6RxlDlqcKb2jh":{"accessTime":1439584930407,"flashMessages":{}}}

0 commit comments

Comments
 (0)