diff --git a/appengine/loopback/.eslintignore b/appengine/loopback/.eslintignore new file mode 100644 index 00000000000..44f397018c4 --- /dev/null +++ b/appengine/loopback/.eslintignore @@ -0,0 +1 @@ +/client/ \ No newline at end of file diff --git a/appengine/loopback/.eslintrc b/appengine/loopback/.eslintrc new file mode 100644 index 00000000000..a6e52975a0f --- /dev/null +++ b/appengine/loopback/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "loopback" +} \ No newline at end of file diff --git a/appengine/loopback/.jshintignore b/appengine/loopback/.jshintignore deleted file mode 100644 index ee8c771c5ad..00000000000 --- a/appengine/loopback/.jshintignore +++ /dev/null @@ -1,2 +0,0 @@ -/client/ -/node_modules/ diff --git a/appengine/loopback/.jshintrc b/appengine/loopback/.jshintrc deleted file mode 100644 index feb092894fa..00000000000 --- a/appengine/loopback/.jshintrc +++ /dev/null @@ -1,21 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "eqeqeq": true, - "eqnull": true, - "immed": true, - "indent": 2, - "latedef": "nofunc", - "newcap": true, - "nonew": true, - "noarg": true, - "quotmark": "single", - "regexp": true, - "undef": true, - "unused": false, - "trailing": true, - "sub": true, - "maxlen": 80 -} diff --git a/appengine/loopback/client/index.html b/appengine/loopback/client/index.html deleted file mode 100644 index c3b7cc826a2..00000000000 --- a/appengine/loopback/client/index.html +++ /dev/null @@ -1,5 +0,0 @@ -LoopBack - -

Hello World!

-

LoopBack.js on Google App Engine.

- \ No newline at end of file diff --git a/appengine/loopback/common/models/message.js b/appengine/loopback/common/models/message.js new file mode 100644 index 00000000000..fc94c5a3be8 --- /dev/null +++ b/appengine/loopback/common/models/message.js @@ -0,0 +1,8 @@ +module.exports = function(Message) { + Message.greet = function(msg, cb) { + process.nextTick(function() { + msg = msg || 'hello'; + cb(null, 'Sender says ' + msg + ' to receiver'); + }); + }; +}; diff --git a/appengine/loopback/common/models/message.json b/appengine/loopback/common/models/message.json new file mode 100644 index 00000000000..4edf66b2835 --- /dev/null +++ b/appengine/loopback/common/models/message.json @@ -0,0 +1,24 @@ +{ + "name": "Message", + "base": "Model", + "properties": {}, + "methods": { + "greet": { + "isStatic": true, + "accepts": [{ + "arg": "msg", + "type": "string", + "http": { + "source": "query" + } + }], + "returns": { + "arg": "greeting", + "type": "string" + }, + "http": { + "verb": "get" + } + } + } +} diff --git a/appengine/loopback/common/models/person.js b/appengine/loopback/common/models/person.js deleted file mode 100644 index 244f6425027..00000000000 --- a/appengine/loopback/common/models/person.js +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -'use strict'; - -module.exports = function(Person) { - -}; diff --git a/appengine/loopback/common/models/person.json b/appengine/loopback/common/models/person.json deleted file mode 100644 index 095bf6a148f..00000000000 --- a/appengine/loopback/common/models/person.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "person", - "plural": "people", - "base": "User", - "idInjection": true, - "options": { - "validateUpsert": true - }, - "properties": { - "name": { - "type": "string", - "required": true - }, - "email": { - "type": "string", - "required": true - } - }, - "validations": [], - "relations": {}, - "acls": [], - "methods": {} -} diff --git a/appengine/loopback/package.json b/appengine/loopback/package.json index c1bbc98c777..14566b745db 100644 --- a/appengine/loopback/package.json +++ b/appengine/loopback/package.json @@ -8,19 +8,26 @@ "engines": { "node": ">=4.3.2" }, + "main": "server/server.js", "scripts": { - "pretest": "jshint .", - "start": "node server/server.js" + "lint": "eslint .", + "start": "node .", + "posttest": "npm run lint && nsp check" }, "dependencies": { - "compression": "1.0.3", - "cors": "2.5.2", - "errorhandler": "1.1.1", - "jshint": "2.5.6", - "loopback": "2.14.0", - "loopback-boot": "2.6.5", - "loopback-datasource-juggler": "2.19.0", - "loopback-explorer": "1.1.0", - "serve-favicon": "2.0.1" + "compression": "^1.0.3", + "cors": "^2.5.2", + "helmet": "^1.3.0", + "loopback-boot": "^2.6.5", + "loopback-component-explorer": "^2.4.0", + "serve-favicon": "^2.0.1", + "strong-error-handler": "^1.0.1", + "loopback-datasource-juggler": "^2.39.0", + "loopback": "^2.22.0" + }, + "devDependencies": { + "eslint": "^2.13.1", + "eslint-config-loopback": "^4.0.0", + "nsp": "^2.1.0" } } diff --git a/appengine/loopback/server/boot/authentication.js b/appengine/loopback/server/boot/authentication.js index a87cd081619..8e88d4b555e 100644 --- a/appengine/loopback/server/boot/authentication.js +++ b/appengine/loopback/server/boot/authentication.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = function enableAuthentication(server) { // enable authentication server.enableAuth(); diff --git a/appengine/loopback/server/boot/explorer.js b/appengine/loopback/server/boot/explorer.js deleted file mode 100644 index e42a69ac6e2..00000000000 --- a/appengine/loopback/server/boot/explorer.js +++ /dev/null @@ -1,27 +0,0 @@ -module.exports = function mountLoopBackExplorer(server) { - var explorer; - try { - explorer = require('loopback-explorer'); - } catch(err) { - // Print the message only when the app was started via `server.listen()`. - // Do not print any message when the project is used as a component. - server.once('started', function(baseUrl) { - console.log( - 'Run `npm install loopback-explorer` to enable the LoopBack explorer' - ); - }); - return; - } - - var restApiRoot = server.get('restApiRoot'); - - var explorerApp = explorer(server, { basePath: restApiRoot }); - server.use('/explorer', explorerApp); - server.once('started', function() { - var baseUrl = server.get('url').replace(/\/$/, ''); - // express 4.x (loopback 2.x) uses `mountpath` - // express 3.x (loopback 1.x) uses `route` - var explorerPath = explorerApp.mountpath || explorerApp.route; - console.log('Browse your REST API at %s%s', baseUrl, explorerPath); - }); -}; diff --git a/appengine/loopback/server/boot/rest-api.js b/appengine/loopback/server/boot/rest-api.js deleted file mode 100644 index 256579a8132..00000000000 --- a/appengine/loopback/server/boot/rest-api.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = function mountRestApi(server) { - var restApiRoot = server.get('restApiRoot'); - server.use(restApiRoot, server.loopback.rest()); -}; diff --git a/appengine/loopback/server/boot/root.js b/appengine/loopback/server/boot/root.js new file mode 100644 index 00000000000..6adce90ad35 --- /dev/null +++ b/appengine/loopback/server/boot/root.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = function(server) { + // Install a `/` route that returns server status + var router = server.loopback.Router(); + router.get('/', server.loopback.status()); + server.use(router); +}; diff --git a/appengine/loopback/server/component-config.json b/appengine/loopback/server/component-config.json new file mode 100644 index 00000000000..f36959a488c --- /dev/null +++ b/appengine/loopback/server/component-config.json @@ -0,0 +1,5 @@ +{ + "loopback-component-explorer": { + "mountPath": "/explorer" + } +} diff --git a/appengine/loopback/server/config.json b/appengine/loopback/server/config.json index 3b1707641b1..40d45f4d637 100644 --- a/appengine/loopback/server/config.json +++ b/appengine/loopback/server/config.json @@ -1,11 +1,9 @@ { "restApiRoot": "/api", "host": "0.0.0.0", - "port": 8080, + "port": 3000, "remoting": { - "context": { - "enableHttpContext": false - }, + "context": false, "rest": { "normalizeHttpPath": false, "xml": false @@ -19,9 +17,7 @@ "limit": "100kb" }, "cors": false, - "errorHandler": { - "disableStackTrace": false - } + "handleErrors": false }, "legacyExplorer": false } diff --git a/appengine/loopback/server/middleware.development.json b/appengine/loopback/server/middleware.development.json new file mode 100644 index 00000000000..071c11a30ee --- /dev/null +++ b/appengine/loopback/server/middleware.development.json @@ -0,0 +1,10 @@ +{ + "final:after": { + "strong-error-handler": { + "params": { + "debug": true, + "log": true + } + } + } +} diff --git a/appengine/loopback/server/middleware.json b/appengine/loopback/server/middleware.json index b1cd5063259..fbfff8165de 100644 --- a/appengine/loopback/server/middleware.json +++ b/appengine/loopback/server/middleware.json @@ -10,21 +10,41 @@ "credentials": true, "maxAge": 86400 } + }, + "helmet#xssFilter": {}, + "helmet#frameguard": { + "params": [ + "deny" + ] + }, + "helmet#hsts": { + "params": { + "maxAge": 0, + "includeSubdomains": true + } + }, + "helmet#hidePoweredBy": {}, + "helmet#ieNoOpen": {}, + "helmet#noSniff": {}, + "helmet#noCache": { + "enabled": false } }, "session": {}, "auth": {}, "parse": {}, - "routes": {}, - "files": { - "loopback#static": { - "params": "$!../client" + "routes": { + "loopback#rest": { + "paths": [ + "${restApiRoot}" + ] } }, + "files": {}, "final": { "loopback#urlNotFound": {} }, "final:after": { - "errorhandler": {} + "strong-error-handler": {} } } diff --git a/appengine/loopback/server/model-config.json b/appengine/loopback/server/model-config.json index 411cb8a401e..30be974de8c 100644 --- a/appengine/loopback/server/model-config.json +++ b/appengine/loopback/server/model-config.json @@ -32,8 +32,7 @@ "dataSource": "db", "public": false }, - "person": { - "dataSource": "db", - "public": true + "Message": { + "dataSource": null } } diff --git a/appengine/loopback/server/server.js b/appengine/loopback/server/server.js index ec3e5443551..ef738abce20 100644 --- a/appengine/loopback/server/server.js +++ b/appengine/loopback/server/server.js @@ -1,19 +1,5 @@ -// 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. - 'use strict'; -// [START server] var loopback = require('loopback'); var boot = require('loopback-boot'); @@ -23,20 +9,21 @@ app.start = function() { // start the web server return app.listen(function() { app.emit('started'); - console.log('Web server listening at: %s', app.get('url')); + var baseUrl = app.get('url').replace(/\/$/, ''); + console.log('Web server listening at: %s', baseUrl); + if (app.get('loopback-component-explorer')) { + var explorerPath = app.get('loopback-component-explorer').mountPath; + console.log('Browse your REST API at %s%s', baseUrl, explorerPath); + } }); }; // Bootstrap the application, configure models, datasources and middleware. // Sub-apps like REST API are mounted via boot scripts. boot(app, __dirname, function(err) { - if (err) { - throw err; - } + if (err) throw err; // start the server if `$ node server.js` - if (require.main === module) { + if (require.main === module) app.start(); - } }); -// [START server] \ No newline at end of file diff --git a/logging/package.json b/logging/package.json index abb9cd91505..990db1599c5 100644 --- a/logging/package.json +++ b/logging/package.json @@ -9,10 +9,10 @@ "system-test": "cd ..; npm run st -- logging/system-test/*.test.js" }, "dependencies": { - "@google-cloud/logging": "0.5.0", - "@google-cloud/storage": "0.4.0", + "@google-cloud/logging": "0.5.1", + "@google-cloud/storage": "0.5.0", "express": "4.14.0", - "fluent-logger": "2.0.1", + "fluent-logger": "2.2.0", "yargs": "6.4.0" }, "devDependencies": { diff --git a/logging/quickstart.js b/logging/quickstart.js index c87353a6070..24e18eaa40d 100644 --- a/logging/quickstart.js +++ b/logging/quickstart.js @@ -20,7 +20,7 @@ const Logging = require('@google-cloud/logging'); // Your Google Cloud Platform project ID -const projectId = 'YOUR_PROJECT_ID'; +const projectId = 'nodejs-docs-samples'; // Instantiates a client const loggingClient = Logging({ diff --git a/trace/package.json b/trace/package.json index c9f3b34a734..88b585f1a8f 100644 --- a/trace/package.json +++ b/trace/package.json @@ -9,7 +9,7 @@ }, "scripts": { "start": "node app.js", - "test": "cd ..; npm run t -- trace/test/*.test.js", + "test": "cd ..; npm run t -- trace/test/*.test.js" }, "dependencies": { "@google/cloud-trace": "0.5.10",