Skip to content
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

Added the new getting-started sample #581

Closed
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
16 changes: 16 additions & 0 deletions appengine-standard/getting-started/build/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2018, 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: nodejs8
# [END app_yaml]
29 changes: 29 additions & 0 deletions appengine-standard/getting-started/build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "appengine-standard-getting-started-build-apps",
"version": "0.0.1",
"description": "Node.js getting started sample for building an app on App Engine standard environment.",
"private": true,
"main": "server.js",
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"test": "ava --verbose test/*.test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": "8.x.x"
},
"author": "Google Inc.",
"license": "Apache-2.0",
"dependencies": {
"express": "^4.16.3"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.22.0",
"semistandard": "^12.0.1"
}
}
33 changes: 33 additions & 0 deletions appengine-standard/getting-started/build/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2018, 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';

// [START app]
const express = require('express');
const app = express();

app.get('/', (req, res) => {
res.send('Hello from App Engine!');
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
// [END app]

module.exports = app;
36 changes: 36 additions & 0 deletions appengine-standard/getting-started/build/test/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2018, 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 path = require(`path`);
const test = require(`ava`);
const utils = require(`@google-cloud/nodejs-repo-tools`);

const cwd = path.join(__dirname, `../`);
const requestObj = utils.getRequest({
cwd: cwd,
cmd: `server` });

test.beforeEach(utils.stubConsole);
test.afterEach.always(utils.restoreConsole);

test.cb.serial(`should send greetings`, (t) => {
requestObj
.get(`/`)
.expect(200)
.expect((response) => {
t.is(response.text, `Hello from App Engine!`);
})
.end(t.end);
});
16 changes: 16 additions & 0 deletions appengine-standard/getting-started/update/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2018, 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: nodejs8
# [END app_yaml]
31 changes: 31 additions & 0 deletions appengine-standard/getting-started/update/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "appengine-standard-getting-started-update-apps",
"version": "0.0.1",
"description": "Node.js getting started sample for updating an app on App Engine standard environment.",
"private": true,
"main": "server.js",
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"test": "ava --verbose test/*.test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": "8.x.x"
},
"author": "Google Inc.",
"license": "Apache-2.0",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.3",
"semistandard": "^12.0.1"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.22.0",
"semistandard": "^12.0.1"
}
}
56 changes: 56 additions & 0 deletions appengine-standard/getting-started/update/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2018, 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';

// [START app]
const express = require('express');
const bodyParser = require('body-parser');
const path = require(`path`);

const app = express();

// [START enable_parser]
app.use(bodyParser.urlencoded({ extended: true }));
// [END enable_parser]

app.get('/', (req, res) => {
res.send('Hello from App Engine!');
});

// [START add_display_form]
app.get('/submit', (req, res) => {
res.sendFile(path.join(__dirname, '/views/form.html'));
});
// [END add_display_form]

// [START add_post_handler]
app.post('/submit', (req, res) => {
console.log({
name: req.body.name,
message: req.body.message
});
res.send('Thanks for your message!');
});
// [END add_post_handler]

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
// [END app]

module.exports = app;
59 changes: 59 additions & 0 deletions appengine-standard/getting-started/update/test/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2018, 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 path = require(`path`);
const test = require(`ava`);
const utils = require(`@google-cloud/nodejs-repo-tools`);

const cwd = path.join(__dirname, `../`);
const requestObj = utils.getRequest({
cwd: cwd,
cmd: `server` });

test.beforeEach(utils.stubConsole);
test.afterEach.always(utils.restoreConsole);

test.cb.serial(`should send greetings`, (t) => {
requestObj
.get(`/`)
.expect(200)
.expect((response) => {
t.is(response.text, `Hello from App Engine!`);
})
.end(t.end);
});

test.cb.serial(`should display form`, (t) => {
requestObj
.get(`/submit`)
.expect(200)
.expect((response) => {
t.regex(response.text, /textarea name="message" placeholder="Message"/);
})
.end(t.end);
});

test.cb.serial(`should record message`, (t) => {
requestObj
.post(`/submit`, {
name: `sample-user`,
message: `sample-message`
})
.expect(200)
.expect((response) => {
t.is(response.text, `Thanks for your message!`);
})
.end(t.end);
});
20 changes: 20 additions & 0 deletions appengine-standard/getting-started/update/views/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>My App Engine App</title>
</head>
<body>
<h2>Create a new post</h2>
<form method="POST" action="/submit">
<div>
<input type="text" name="name" placeholder="Name">
</div>
<div>
<textarea name="message" placeholder="Message"></textarea>
</div>
<div>
<button type="submit">Submit</button>
</div>
</form>
</body>
</html>