Skip to content

Revert "Upgrade apps for env:flex." #242

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

Merged
merged 1 commit into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appengine/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Google App Engine Node.js Samples

These are samples for using Node.js on Google App Engine Flexible Environment. These
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)
Expand Down
2 changes: 1 addition & 1 deletion appengine/analytics/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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 Flexible Environment](https://cloud.google.com/appengine).
(or any other SQL server) on [Google App Engine Managed VMs](https://cloud.google.com/appengine).

## Setup

Expand Down
61 changes: 28 additions & 33 deletions appengine/analytics/app.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
/**
* 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.
*/
// Copyright 2015-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';

// [START setup]
const express = require('express');
const request = require('request');
var express = require('express');
var request = require('request');

const app = express();
var app = express();
app.enable('trust proxy');
// [END setup]

// [START track]
// 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.
const GA_TRACKING_ID = process.env.GA_TRACKING_ID;
var GA_TRACKING_ID = process.env.GA_TRACKING_ID;

function trackEvent (category, action, label, value, cb) {
const data = {
var data = {
v: '1', // API Version.
tid: GA_TRACKING_ID, // Tracking ID / Property ID.
// Anonymous Client Identifier. Ideally, this should be a UUID that
Expand All @@ -44,18 +43,15 @@ function trackEvent (category, action, label, value, cb) {
};

request.post(
'http://www.google-analytics.com/collect',
{
'http://www.google-analytics.com/collect', {
form: data
},
(err, response) => {
function (err, response) {
if (err) {
cb(err);
return;
return cb(err);
}
if (response.statusCode !== 200) {
cb(new Error('Tracking failed'));
return;
return cb(new Error('Tracking failed'));
}
cb();
}
Expand All @@ -64,29 +60,28 @@ function trackEvent (category, action, label, value, cb) {
// [END track]

// [START endpoint]
app.get('/', (req, res, next) => {
app.get('/', function (req, res, next) {
trackEvent(
'Example category',
'Example action',
'Example label',
'100', // Event value must be numeric.
(err) => {
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) {
next(err);
return;
return next(err);
}
res.status(200).send('Event tracked.');
});
});
// [END endpoint]

// [START listen]
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
var PORT = process.env.PORT || 8080;
app.listen(PORT, function () {
console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
});
// [END listen]
Expand Down
4 changes: 2 additions & 2 deletions appengine/analytics/app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016, Google, Inc.
# Copyright 2015-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
Expand All @@ -13,7 +13,7 @@

# [START app_yaml]
runtime: nodejs
env: flex
vm: true

# [START env]
env_variables:
Expand Down
8 changes: 4 additions & 4 deletions appengine/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": ">=4.3.2"
"node": "~4.2"
},
"scripts": {
"start": "node app.js",
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.14.0",
"request": "^2.75.0"
"express": "^4.13.4",
"request": "^2.69.0"
},
"devDependencies": {
"mocha": "^3.1.0"
"mocha": "^2.5.3"
}
}
81 changes: 39 additions & 42 deletions appengine/analytics/test/app.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
/**
* 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.
*/
// 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.

'use strict';

const express = require(`express`);
const path = require(`path`);
const proxyquire = require(`proxyquire`).noPreserveCache();
const request = require(`supertest`);
var express = require('express');
var path = require('path');
var proxyquire = require('proxyquire').noPreserveCache();
var request = require('supertest');

const SAMPLE_PATH = path.join(__dirname, `../app.js`);
var SAMPLE_PATH = path.join(__dirname, '../app.js');

function getSample () {
const testApp = express();
sinon.stub(testApp, `listen`).callsArg(1);
const expressMock = sinon.stub().returns(testApp);
const resultsMock = {
var testApp = express();
sinon.stub(testApp, 'listen').callsArg(1);
var expressMock = sinon.stub().returns(testApp);
var resultsMock = {
statusCode: 200,
foo: `bar`
foo: 'bar'
};

const requestMock = {
post: sinon.stub().yields(null, resultsMock)
var requestMock = {
post: sinon.stub().callsArgWith(2, null, resultsMock)
};

const app = proxyquire(SAMPLE_PATH, {
var app = proxyquire(SAMPLE_PATH, {
request: requestMock,
express: expressMock
});

return {
app: app,
mocks: {
Expand All @@ -50,52 +47,52 @@ function getSample () {
};
}

describe(`appengine/analytics/app.js`, () => {
let sample;
describe('appengine/analytics/app.js', function () {
var sample;

beforeEach(() => {
beforeEach(function () {
sample = getSample();

assert(sample.mocks.express.calledOnce);
assert(sample.app.listen.calledOnce);
assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
});

it(`should record a visit`, (done) => {
const expectedResult = `Event tracked.`;
it('should record a visit', function (done) {
var expectedResult = 'Event tracked.';

request(sample.app)
.get(`/`)
.get('/')
.expect(200)
.expect((response) => {
.expect(function (response) {
assert.equal(response.text, expectedResult);
})
.end(done);
});

it(`should handle request error`, (done) => {
const expectedResult = `request_error`;
it('should handle request error', function (done) {
var expectedResult = 'request_error';

sample.mocks.request.post.onFirstCall().callsArgWith(2, expectedResult);

request(sample.app)
.get(`/`)
.get('/')
.expect(500)
.expect((response) => {
assert.equal(response.text, expectedResult + `\n`);
.expect(function (response) {
assert.equal(response.text, expectedResult + '\n');
})
.end(done);
});

it(`should handle track error`, (done) => {
it('should handle track error', function (done) {
sample.mocks.request.post.onFirstCall().callsArgWith(2, null, {
statusCode: 400
});

request(sample.app)
.get('/')
.expect(500)
.expect((response) => {
.expect(function (response) {
assert.notEqual(response.text.indexOf('Error: Tracking failed'), -1);
})
.end(done);
Expand Down
4 changes: 2 additions & 2 deletions appengine/bower/app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016, Google, Inc.
# Copyright 2015-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
Expand All @@ -13,5 +13,5 @@

# [START app_yaml]
runtime: nodejs
env: flex
vm: true
# [END app_yaml]
10 changes: 5 additions & 5 deletions appengine/bower/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": ">=4.3.2"
"node": "~4.2"
},
"scripts": {
"postinstall": "bower install --config.interactive=false",
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"bower": "^1.7.9",
"express": "^4.14.0",
"pug": "^2.0.0-beta6"
"bower": "^1.7.7",
"express": "^4.13.4",
"jade": "^1.11.0"
},
"devDependencies": {
"mocha": "^3.1.0"
"mocha": "^2.5.3"
}
}
Loading