-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Showing
146 changed files
with
1,856 additions
and
180 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
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
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,51 @@ | ||
# Google App Engine Node.js Samples | ||
|
||
These are samples for using Node.js on Google App Engine Managed VMs. These | ||
samples are referenced from the [docs](https://cloud.google.com/appengine/docs). | ||
|
||
See our other [Google Cloud Platform github repos](https://github.com/GoogleCloudPlatform) | ||
for sample applications and scaffolding for other frameworks and use cases. | ||
|
||
## Run Locally | ||
|
||
Some samples have specific instructions. If there is a README in the sample | ||
folder, please refer to it for any additional steps required to run the sample. | ||
|
||
In general, the samples typically require: | ||
|
||
1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the | ||
[gcloud tool](https://cloud.google.com/sdk/gcloud/), and | ||
[gcloud app component](https://cloud.google.com/sdk/gcloud-app). | ||
1. Setup the gcloud tool. This provides authentication to Google Cloud APIs and | ||
services. | ||
|
||
gcloud init | ||
|
||
1. Clone this repo. | ||
|
||
git clone https://github.com/GoogleCloudPlatform/<REPO NAME>.git | ||
|
||
1. Open a sample folder, install dependencies, and run the sample: | ||
|
||
cd <sample-folder>/ | ||
npm install | ||
npm start | ||
|
||
1. Visit the application at [http://localhost:8080](http://localhost:8080). | ||
|
||
## Deploying | ||
|
||
Some samples in this repositories may have special deployment instructions. | ||
Refer to the README file in the sample folder. | ||
|
||
1. Use the [Google Developers Console](https://console.developer.google.com) to | ||
create a project/app id. (App id and project id are identical.) | ||
1. Setup the gcloud tool, if you haven't already. | ||
|
||
gcloud init | ||
|
||
1. Use gcloud to deploy your app. | ||
|
||
gcloud preview app deploy | ||
|
||
1. Awesome! Your application is now live at `your-app-id.appspot.com`. |
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,23 @@ | ||
# Google Analytics Measurement Protocol on Google App Engine | ||
|
||
This sample demonstrates how to use the [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/) | ||
(or any other SQL server) on [Google App Engine Managed VMs](https://cloud.google.com/appengine). | ||
|
||
## Setup | ||
|
||
Before you can run or deploy the sample, you need to do the following: | ||
|
||
1. Create a Google Analytics Property and obtain the Tracking ID. | ||
1. Update the environment variables in in `app.yaml` with your Tracking ID. | ||
|
||
## Running locally | ||
|
||
Refer to the [appengine/README.md](../README.md) file for instructions on | ||
running and deploying. | ||
|
||
To run locally, set the environment variables via your shell before running the | ||
sample: | ||
|
||
export GA_TRACKING_ID=<your-tracking-id> | ||
npm install | ||
npm start |
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,76 @@ | ||
// Copyright 2016, 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 app] | ||
'use strict'; | ||
|
||
var express = require('express'); | ||
var request = require('request'); | ||
|
||
var app = express(); | ||
|
||
// The following environment variable is set by app.yaml when running on GAE, | ||
// but will need to be manually set when running locally. See README.md. | ||
var GA_TRACKING_ID = process.env.GA_TRACKING_ID; | ||
|
||
function trackEvent(category, action, label, value, cb) { | ||
var data = { | ||
v: '1', // API Version. | ||
tid: GA_TRACKING_ID, // Tracking ID / Property ID. | ||
// Anonymous Client Identifier. Ideally, this should be a UUID that | ||
// is associated with particular user, device, or browser instance. | ||
cid: '555', | ||
t: 'event', // Event hit type. | ||
ec: category, // Event category. | ||
ea: action, // Event action. | ||
el: label, // Event label. | ||
ev: value, // Event value. | ||
}; | ||
|
||
request.post( | ||
'http://www.google-analytics.com/collect', { | ||
form: data | ||
}, | ||
function(err, response) { | ||
if (err) { return cb(err); } | ||
if (response.statusCode !== 200) { | ||
return cb(new Error('Tracking failed')); | ||
} | ||
cb(); | ||
} | ||
); | ||
} | ||
|
||
app.get('/', function(req, res, next) { | ||
trackEvent( | ||
'Example category', | ||
'Example action', | ||
'Example label', | ||
'100', // Event value must be numeric. | ||
function(err) { | ||
// This sample treats an event tracking error as a fatal error. Depending | ||
// on your application's needs, failing to track an event may not be | ||
// considered an error. | ||
if (err) { return next(err); } | ||
res.status(200).send('Event tracked.'); | ||
}); | ||
}); | ||
|
||
// Start the server | ||
var server = app.listen(process.env.PORT || '8080', '0.0.0.0', function() { | ||
console.log('App listening at http://%s:%s', server.address().address, | ||
server.address().port); | ||
console.log('Press Ctrl+C to quit.'); | ||
}); | ||
// [END app] |
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,25 @@ | ||
# Copyright 2016, 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 app_yaml] | ||
runtime: nodejs | ||
vm: true | ||
|
||
# [START env] | ||
env_variables: | ||
GA_TRACKING_ID: <your-tracking-id> | ||
# [END env] | ||
|
||
skip_files: | ||
- ^(.*/)?.*/node_modules/.*$ | ||
# [END app_yaml] |
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,20 @@ | ||
{ | ||
"name": "appengine-analytics", | ||
"description": "Sample for Google Analytics Measurement Protocol on Google App Engine", | ||
"version": "0.0.1", | ||
"private": true, | ||
"license": "Apache Version 2.0", | ||
"author": "Google Inc.", | ||
"engines": { | ||
"node": "~4.2" | ||
}, | ||
"scripts": { | ||
"start": "node app.js", | ||
"monitor": "nodemon app.js", | ||
"deploy": "gcloud preview app deploy" | ||
}, | ||
"dependencies": { | ||
"express": "^4.13.3", | ||
"request": "^2.67.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## Bower on Google App Engine | ||
# Bower on Google App Engine | ||
|
||
> [Bower][1]: A package manager for the web. | ||
|
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
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
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
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
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,40 @@ | ||
# Node.js Cloud SQL sample on Google App Engine | ||
|
||
This sample demonstrates how to use [Cloud SQL](https://cloud.google.com/sql/) | ||
on [Google App Engine Managed VMs](https://cloud.google.com/appengine). | ||
|
||
## Setup | ||
|
||
Before you can run or deploy the sample, you will need to do the following: | ||
|
||
1. Create a Cloud SQL instance. You can do this from the [Google Developers Console](https://console.developers.google.com) | ||
or via the [Cloud SDK](https://cloud.google.com/sdk). To create it via the SDK | ||
use the following command: | ||
|
||
gcloud sql instances create [your-instance-name] \ | ||
--assign-ip \ | ||
--authorized-networks 0.0.0.0/0 \ | ||
--tier D0 | ||
|
||
1. Create a new user and database for the application. The easiest way to do | ||
this is via the [Google Developers Console](https://console.developers.google.com/project/_/sql/instances/example-instance2/access-control/users). | ||
Alternatively, you can use MySQL tools such as the command line client or | ||
workbench. | ||
1. Update the values in in `app.yaml` with your instance configuration. | ||
1. Finally, run `create_tables.js` to ensure that the database is properly | ||
configured and to create the tables needed for the sample. | ||
|
||
## Running locally | ||
|
||
Refer to the [appengine/README.md](../README.md) file for instructions on | ||
running and deploying. | ||
|
||
To run locally, set the environment variables via your shell before running the | ||
sample: | ||
|
||
export MYSQL_HOST=<your-cloudsql-host> | ||
export MYSQL_USER=<your-cloudsql-user> | ||
export MYSQL_PASSWORD=<your-cloudsql-password> | ||
export MYSQL_DATABASE=<your-cloudsql-database> | ||
npm install | ||
npm start |
Oops, something went wrong.