Skip to content

Commit 81df6cc

Browse files
authored
Upgrade GAE apps to env: flex (GoogleCloudPlatform#253)
1 parent 2cf8055 commit 81df6cc

File tree

167 files changed

+1830
-1907
lines changed

Some content is hidden

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

167 files changed

+1830
-1907
lines changed

appengine/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Google App Engine Node.js Samples
22

3-
These are samples for using Node.js on Google App Engine Managed VMs. These
3+
These are samples for using Node.js on Google App Engine Flexible Environment. These
44
samples are referenced from the [docs](https://cloud.google.com/appengine/docs).
55

66
See our other [Google Cloud Platform github repos](https://github.com/GoogleCloudPlatform)

appengine/analytics/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Google Analytics Measurement Protocol on Google App Engine
22

33
This sample demonstrates how to use the [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/)
4-
(or any other SQL server) on [Google App Engine Managed VMs](https://cloud.google.com/appengine).
4+
(or any other SQL server) on [Google App Engine Flexible Environment](https://cloud.google.com/appengine).
55

66
## Setup
77

appengine/analytics/app.js

+33-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
// Copyright 2015-2016, Google, Inc.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1415

1516
// [START app]
1617
'use strict';
1718

1819
// [START setup]
19-
var express = require('express');
20-
var request = require('request');
20+
const express = require('express');
21+
const request = require('request');
2122

22-
var app = express();
23+
const app = express();
2324
app.enable('trust proxy');
2425
// [END setup]
2526

2627
// [START track]
2728
// The following environment variable is set by app.yaml when running on GAE,
2829
// but will need to be manually set when running locally. See README.md.
29-
var GA_TRACKING_ID = process.env.GA_TRACKING_ID;
30+
const GA_TRACKING_ID = process.env.GA_TRACKING_ID;
3031

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

4546
request.post(
46-
'http://www.google-analytics.com/collect', {
47+
'http://www.google-analytics.com/collect',
48+
{
4749
form: data
4850
},
49-
function (err, response) {
51+
(err, response) => {
5052
if (err) {
51-
return cb(err);
53+
cb(err);
54+
return;
5255
}
5356
if (response.statusCode !== 200) {
54-
return cb(new Error('Tracking failed'));
57+
cb(new Error('Tracking failed'));
58+
return;
5559
}
5660
cb();
5761
}
@@ -60,28 +64,29 @@ function trackEvent (category, action, label, value, cb) {
6064
// [END track]
6165

6266
// [START endpoint]
63-
app.get('/', function (req, res, next) {
67+
app.get('/', (req, res, next) => {
6468
trackEvent(
6569
'Example category',
6670
'Example action',
6771
'Example label',
6872
'100', // Event value must be numeric.
69-
function (err) {
73+
(err) => {
7074
// This sample treats an event tracking error as a fatal error. Depending
7175
// on your application's needs, failing to track an event may not be
7276
// considered an error.
7377
if (err) {
74-
return next(err);
78+
next(err);
79+
return;
7580
}
7681
res.status(200).send('Event tracked.');
7782
});
7883
});
7984
// [END endpoint]
8085

8186
// [START listen]
82-
var PORT = process.env.PORT || 8080;
83-
app.listen(PORT, function () {
84-
console.log('App listening on port %s', PORT);
87+
const PORT = process.env.PORT || 8080;
88+
app.listen(PORT, () => {
89+
console.log(`App listening on port ${PORT}`);
8590
console.log('Press Ctrl+C to quit.');
8691
});
8792
// [END listen]

appengine/analytics/app.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015-2016, Google, Inc.
1+
# Copyright 2016, Google, Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -13,7 +13,7 @@
1313

1414
# [START app_yaml]
1515
runtime: nodejs
16-
vm: true
16+
env: flex
1717

1818
# [START env]
1919
env_variables:

appengine/analytics/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"license": "Apache Version 2.0",
77
"author": "Google Inc.",
88
"engines": {
9-
"node": "~4.2"
9+
"node": ">=4.3.2"
1010
},
1111
"scripts": {
1212
"start": "node app.js",
1313
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
1414
},
1515
"dependencies": {
16-
"express": "^4.13.4",
17-
"request": "^2.69.0"
16+
"express": "^4.14.0",
17+
"request": "^2.75.0"
1818
},
1919
"devDependencies": {
20-
"mocha": "^2.5.3"
20+
"mocha": "^3.1.0"
2121
}
2222
}

appengine/analytics/test/app.test.js

+42-39
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
// Copyright 2016, 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.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

16-
var express = require('express');
17-
var path = require('path');
18-
var proxyquire = require('proxyquire').noPreserveCache();
19-
var request = require('supertest');
18+
const express = require(`express`);
19+
const path = require(`path`);
20+
const proxyquire = require(`proxyquire`).noPreserveCache();
21+
const request = require(`supertest`);
2022

21-
var SAMPLE_PATH = path.join(__dirname, '../app.js');
23+
const SAMPLE_PATH = path.join(__dirname, `../app.js`);
2224

2325
function getSample () {
24-
var testApp = express();
25-
sinon.stub(testApp, 'listen').callsArg(1);
26-
var expressMock = sinon.stub().returns(testApp);
27-
var resultsMock = {
26+
const testApp = express();
27+
sinon.stub(testApp, `listen`).callsArg(1);
28+
const expressMock = sinon.stub().returns(testApp);
29+
const resultsMock = {
2830
statusCode: 200,
29-
foo: 'bar'
31+
foo: `bar`
3032
};
3133

32-
var requestMock = {
33-
post: sinon.stub().callsArgWith(2, null, resultsMock)
34+
const requestMock = {
35+
post: sinon.stub().yields(null, resultsMock)
3436
};
3537

36-
var app = proxyquire(SAMPLE_PATH, {
38+
const app = proxyquire(SAMPLE_PATH, {
3739
request: requestMock,
3840
express: expressMock
3941
});
42+
4043
return {
4144
app: app,
4245
mocks: {
@@ -47,52 +50,52 @@ function getSample () {
4750
};
4851
}
4952

50-
describe('appengine/analytics/app.js', function () {
51-
var sample;
53+
describe(`appengine/analytics/app.js`, () => {
54+
let sample;
5255

53-
beforeEach(function () {
56+
beforeEach(() => {
5457
sample = getSample();
5558

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

61-
it('should record a visit', function (done) {
62-
var expectedResult = 'Event tracked.';
64+
it(`should record a visit`, (done) => {
65+
const expectedResult = `Event tracked.`;
6366

6467
request(sample.app)
65-
.get('/')
68+
.get(`/`)
6669
.expect(200)
67-
.expect(function (response) {
70+
.expect((response) => {
6871
assert.equal(response.text, expectedResult);
6972
})
7073
.end(done);
7174
});
7275

73-
it('should handle request error', function (done) {
74-
var expectedResult = 'request_error';
76+
it(`should handle request error`, (done) => {
77+
const expectedResult = `request_error`;
7578

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

7881
request(sample.app)
79-
.get('/')
82+
.get(`/`)
8083
.expect(500)
81-
.expect(function (response) {
82-
assert.equal(response.text, expectedResult + '\n');
84+
.expect((response) => {
85+
assert.equal(response.text, expectedResult + `\n`);
8386
})
8487
.end(done);
8588
});
8689

87-
it('should handle track error', function (done) {
90+
it(`should handle track error`, (done) => {
8891
sample.mocks.request.post.onFirstCall().callsArgWith(2, null, {
8992
statusCode: 400
9093
});
9194

9295
request(sample.app)
9396
.get('/')
9497
.expect(500)
95-
.expect(function (response) {
98+
.expect((response) => {
9699
assert.notEqual(response.text.indexOf('Error: Tracking failed'), -1);
97100
})
98101
.end(done);

appengine/bower/app.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015-2016, Google, Inc.
1+
# Copyright 2016, Google, Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -13,5 +13,5 @@
1313

1414
# [START app_yaml]
1515
runtime: nodejs
16-
vm: true
16+
env: flex
1717
# [END app_yaml]

appengine/bower/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
"license": "Apache Version 2.0",
77
"author": "Google Inc.",
88
"engines": {
9-
"node": "~4.2"
9+
"node": ">=4.3.2"
1010
},
1111
"scripts": {
1212
"postinstall": "bower install --config.interactive=false",
1313
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
1414
},
1515
"dependencies": {
16-
"bower": "^1.7.7",
17-
"express": "^4.13.4",
18-
"jade": "^1.11.0"
16+
"bower": "^1.7.9",
17+
"express": "^4.14.0",
18+
"pug": "^2.0.0-beta6"
1919
},
2020
"devDependencies": {
21-
"mocha": "^2.5.3"
21+
"mocha": "^3.1.0"
2222
}
2323
}

0 commit comments

Comments
 (0)