From 40838db844e865d7612b6bbd0a482dda3f18840c Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Fri, 11 Nov 2016 16:15:48 -0500 Subject: [PATCH] Initial commit --- .editorconfig | 13 +++++++ .eslintignore | 1 + .eslintrc | 3 ++ .gitignore | 19 ++++++++++ .yo-rc.json | 3 ++ README.md | 15 ++++++++ bin/arcdemo.mysqldump.sql | 52 +++++++++++++++++++++++++++ bin/arcdemo.sql | 52 +++++++++++++++++++++++++++ bin/demo.mysqldump.sql | 52 +++++++++++++++++++++++++++ bin/demo.sql | 13 +++++++ client/README.md | 3 ++ client/index.html | 5 +++ common/models/coffee-shop.js | 25 +++++++++++++ common/models/coffee-shop.json | 22 ++++++++++++ package.json | 33 ++++++++++++++++++ server/boot/authentication.js | 6 ++++ server/boot/create-sample-models.js | 17 +++++++++ server/boot/root.js | 7 ++++ server/boot/routes.js | 8 +++++ server/component-config.json | 5 +++ server/config.json | 23 ++++++++++++ server/datasources.json | 16 +++++++++ server/middleware.development.json | 10 ++++++ server/middleware.json | 54 +++++++++++++++++++++++++++++ server/model-config.json | 39 +++++++++++++++++++++ server/server.js | 29 ++++++++++++++++ 26 files changed, 525 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .yo-rc.json create mode 100644 README.md create mode 100644 bin/arcdemo.mysqldump.sql create mode 100644 bin/arcdemo.sql create mode 100644 bin/demo.mysqldump.sql create mode 100644 bin/demo.sql create mode 100644 client/README.md create mode 100644 client/index.html create mode 100644 common/models/coffee-shop.js create mode 100644 common/models/coffee-shop.json create mode 100644 package.json create mode 100644 server/boot/authentication.js create mode 100644 server/boot/create-sample-models.js create mode 100644 server/boot/root.js create mode 100644 server/boot/routes.js create mode 100644 server/component-config.json create mode 100644 server/config.json create mode 100644 server/datasources.json create mode 100644 server/middleware.development.json create mode 100644 server/middleware.json create mode 100644 server/model-config.json create mode 100644 server/server.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3ee22e5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..44f3970 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/client/ \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..a6e5297 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "loopback" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aff1045 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +*.csv +*.dat +*.iml +*.log +*.out +*.pid +*.seed +*.sublime-* +*.swo +*.swp +*.tgz +*.xml +.DS_Store +.idea +.project +.strong-pm +coverage +node_modules +npm-debug.log diff --git a/.yo-rc.json b/.yo-rc.json new file mode 100644 index 0000000..02f3fc1 --- /dev/null +++ b/.yo-rc.json @@ -0,0 +1,3 @@ +{ + "generator-loopback": {} +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..50d87f1 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +**PLEASE CREATE ISSUES AT https://github.com/strongloop/loopback/issues** + +--- + +#loopback-getting-started + +This is the example application that accompanies the [Getting started with LoopBack](http://docs.strongloop.com/display/LB/Getting+started+with+LoopBack) tutorial. Follow the steps in the tutorial to create this application from scratch. + +NOTE: This repository has commits for each step of the tutorial, so you can pick up the tutorial at any point along the way: + +See [Getting started with LoopBack](http://docs.strongloop.com/display/LB/Getting+started+with+LoopBack) for step-by-step instructions to create this application. + +--- + +[More LoopBack examples](https://github.com/strongloop/loopback-example) diff --git a/bin/arcdemo.mysqldump.sql b/bin/arcdemo.mysqldump.sql new file mode 100644 index 0000000..d40ebaf --- /dev/null +++ b/bin/arcdemo.mysqldump.sql @@ -0,0 +1,52 @@ +-- MySQL dump 10.13 Distrib 5.6.20, for osx10.8 (x86_64) +-- +-- Host: localhost Database: getting_started +-- ------------------------------------------------------ +-- Server version 5.6.20 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `CoffeeShop` +-- + +DROP TABLE IF EXISTS `CoffeeShop`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `CoffeeShop` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(512) DEFAULT NULL, + `city` varchar(512) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `CoffeeShop` +-- + +LOCK TABLES `CoffeeShop` WRITE; +/*!40000 ALTER TABLE `CoffeeShop` DISABLE KEYS */; +INSERT INTO `CoffeeShop` VALUES (1,'Bel Cafe','Vancouver'),(2,'Three Bees Coffee House','San Mateo'),(3,'Caffe Artigiano','Vancouver'); +/*!40000 ALTER TABLE `CoffeeShop` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2014-12-03 13:55:19 diff --git a/bin/arcdemo.sql b/bin/arcdemo.sql new file mode 100644 index 0000000..d40ebaf --- /dev/null +++ b/bin/arcdemo.sql @@ -0,0 +1,52 @@ +-- MySQL dump 10.13 Distrib 5.6.20, for osx10.8 (x86_64) +-- +-- Host: localhost Database: getting_started +-- ------------------------------------------------------ +-- Server version 5.6.20 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `CoffeeShop` +-- + +DROP TABLE IF EXISTS `CoffeeShop`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `CoffeeShop` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(512) DEFAULT NULL, + `city` varchar(512) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `CoffeeShop` +-- + +LOCK TABLES `CoffeeShop` WRITE; +/*!40000 ALTER TABLE `CoffeeShop` DISABLE KEYS */; +INSERT INTO `CoffeeShop` VALUES (1,'Bel Cafe','Vancouver'),(2,'Three Bees Coffee House','San Mateo'),(3,'Caffe Artigiano','Vancouver'); +/*!40000 ALTER TABLE `CoffeeShop` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2014-12-03 13:55:19 diff --git a/bin/demo.mysqldump.sql b/bin/demo.mysqldump.sql new file mode 100644 index 0000000..d40ebaf --- /dev/null +++ b/bin/demo.mysqldump.sql @@ -0,0 +1,52 @@ +-- MySQL dump 10.13 Distrib 5.6.20, for osx10.8 (x86_64) +-- +-- Host: localhost Database: getting_started +-- ------------------------------------------------------ +-- Server version 5.6.20 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `CoffeeShop` +-- + +DROP TABLE IF EXISTS `CoffeeShop`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `CoffeeShop` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(512) DEFAULT NULL, + `city` varchar(512) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `CoffeeShop` +-- + +LOCK TABLES `CoffeeShop` WRITE; +/*!40000 ALTER TABLE `CoffeeShop` DISABLE KEYS */; +INSERT INTO `CoffeeShop` VALUES (1,'Bel Cafe','Vancouver'),(2,'Three Bees Coffee House','San Mateo'),(3,'Caffe Artigiano','Vancouver'); +/*!40000 ALTER TABLE `CoffeeShop` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2014-12-03 13:55:19 diff --git a/bin/demo.sql b/bin/demo.sql new file mode 100644 index 0000000..49382b2 --- /dev/null +++ b/bin/demo.sql @@ -0,0 +1,13 @@ +-- Drop `CoffeeShop` table if it exists +DROP TABLE IF EXISTS `CoffeeShop`; + +-- Create a new `CoffeeShop` table +CREATE TABLE `CoffeeShop` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(512) DEFAULT NULL, + `city` varchar(512) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; + +-- Insert values into the new `CoffeeShop` table +INSERT INTO `CoffeeShop` VALUES (1,'Bel Cafe','Vancouver'),(2,'Three Bees Coffee House','San Mateo'),(3,'Caffe Artigiano','Vancouver'); diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..dd00c9e --- /dev/null +++ b/client/README.md @@ -0,0 +1,3 @@ +## Client + +This is the place for your application front-end files. diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..d805393 --- /dev/null +++ b/client/index.html @@ -0,0 +1,5 @@ +LoopBack + +

LoopBack Rocks!

+

Hello World...

+ diff --git a/common/models/coffee-shop.js b/common/models/coffee-shop.js new file mode 100644 index 0000000..598e584 --- /dev/null +++ b/common/models/coffee-shop.js @@ -0,0 +1,25 @@ +'use strict'; + +module.exports = function(CoffeeShop) { + CoffeeShop.status = function(cb) { + var currentDate = new Date(); + var currentHour = currentDate.getHours(); + var OPEN_HOUR = 6; + var CLOSE_HOUR = 20; + console.log('Current hour is ' + currentHour); + var response; + if (currentHour > OPEN_HOUR && currentHour < CLOSE_HOUR) { + response = 'We are open for business.'; + } else { + response = 'Sorry, we are closed. Open daily from 6am to 8pm.'; + } + cb(null, response); + }; + CoffeeShop.remoteMethod( + 'status', + { + http: {path: '/status', verb: 'get'}, + returns: {arg: 'status', type: 'string'}, + } + ); +}; diff --git a/common/models/coffee-shop.json b/common/models/coffee-shop.json new file mode 100644 index 0000000..f822b36 --- /dev/null +++ b/common/models/coffee-shop.json @@ -0,0 +1,22 @@ +{ + "name": "CoffeeShop", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": { + "name": { + "type": "string", + "required": true + }, + "city": { + "type": "string", + "required": true + } + }, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..69d555f --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "loopback-getting-started", + "version": "1.0.0", + "main": "server/server.js", + "scripts": { + "lint": "eslint .", + "start": "node .", + "posttest": "npm run lint && nsp check" + }, + "dependencies": { + "compression": "^1.0.3", + "cors": "^2.5.2", + "helmet": "^1.3.0", + "loopback": "^2.22.0", + "loopback-boot": "^2.6.5", + "loopback-component-explorer": "^2.4.0", + "loopback-connector-mysql": "^2.3.0", + "loopback-datasource-juggler": "^2.39.0", + "serve-favicon": "^2.0.1", + "strong-error-handler": "^1.0.1" + }, + "devDependencies": { + "eslint": "^2.13.1", + "eslint-config-loopback": "^4.0.0", + "nsp": "^2.1.0" + }, + "repository": { + "type": "", + "url": "" + }, + "license": "UNLICENSED", + "description": "loopback-getting-started" +} diff --git a/server/boot/authentication.js b/server/boot/authentication.js new file mode 100644 index 0000000..8e88d4b --- /dev/null +++ b/server/boot/authentication.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = function enableAuthentication(server) { + // enable authentication + server.enableAuth(); +}; diff --git a/server/boot/create-sample-models.js b/server/boot/create-sample-models.js new file mode 100644 index 0000000..823d293 --- /dev/null +++ b/server/boot/create-sample-models.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = function(app) { + app.dataSources.mysqlDs.automigrate('CoffeeShop', function(err) { + if (err) throw err; + + app.models.CoffeeShop.create([ + {name: 'Bel Cafe', city: 'Vancouver'}, + {name: 'Three Bees Coffee House', city: 'San Mateo'}, + {name: 'Caffe Artigiano', city: 'Vancouver'}, + ], function(err, coffeeShops) { + if (err) throw err; + + console.log('Models created: \n', coffeeShops); + }); + }); +}; diff --git a/server/boot/root.js b/server/boot/root.js new file mode 100644 index 0000000..2b9f886 --- /dev/null +++ b/server/boot/root.js @@ -0,0 +1,7 @@ +'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/server/boot/routes.js b/server/boot/routes.js new file mode 100644 index 0000000..22bbf3a --- /dev/null +++ b/server/boot/routes.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = function(app) { + // Install a "/ping" route that returns "pong" + app.get('/ping', function(req, res) { + res.send('pong'); + }); +}; diff --git a/server/component-config.json b/server/component-config.json new file mode 100644 index 0000000..f36959a --- /dev/null +++ b/server/component-config.json @@ -0,0 +1,5 @@ +{ + "loopback-component-explorer": { + "mountPath": "/explorer" + } +} diff --git a/server/config.json b/server/config.json new file mode 100644 index 0000000..40d45f4 --- /dev/null +++ b/server/config.json @@ -0,0 +1,23 @@ +{ + "restApiRoot": "/api", + "host": "0.0.0.0", + "port": 3000, + "remoting": { + "context": false, + "rest": { + "normalizeHttpPath": false, + "xml": false + }, + "json": { + "strict": false, + "limit": "100kb" + }, + "urlencoded": { + "extended": true, + "limit": "100kb" + }, + "cors": false, + "handleErrors": false + }, + "legacyExplorer": false +} diff --git a/server/datasources.json b/server/datasources.json new file mode 100644 index 0000000..82ed88a --- /dev/null +++ b/server/datasources.json @@ -0,0 +1,16 @@ +{ + "db": { + "name": "db", + "connector": "memory" + }, + "mysqlDs": { + "host": "demo.strongloop.com", + "port": 3306, + "url": "", + "database": "getting_started", + "password": "L00pBack", + "name": "mysqlDs", + "user": "demo", + "connector": "mysql" + } +} diff --git a/server/middleware.development.json b/server/middleware.development.json new file mode 100644 index 0000000..071c11a --- /dev/null +++ b/server/middleware.development.json @@ -0,0 +1,10 @@ +{ + "final:after": { + "strong-error-handler": { + "params": { + "debug": true, + "log": true + } + } + } +} diff --git a/server/middleware.json b/server/middleware.json new file mode 100644 index 0000000..1e571c5 --- /dev/null +++ b/server/middleware.json @@ -0,0 +1,54 @@ +{ + "initial:before": { + "loopback#favicon": {} + }, + "initial": { + "compression": {}, + "cors": { + "params": { + "origin": true, + "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": { + "loopback#rest": { + "paths": [ + "${restApiRoot}" + ] + } + }, + "files": { + "loopback#static": { + "params": "$!../client" + } + }, + "final": { + "loopback#urlNotFound": {} + }, + "final:after": { + "strong-error-handler": {} + } +} diff --git a/server/model-config.json b/server/model-config.json new file mode 100644 index 0000000..153f8dd --- /dev/null +++ b/server/model-config.json @@ -0,0 +1,39 @@ +{ + "_meta": { + "sources": [ + "loopback/common/models", + "loopback/server/models", + "../common/models", + "./models" + ], + "mixins": [ + "loopback/common/mixins", + "loopback/server/mixins", + "../common/mixins", + "./mixins" + ] + }, + "User": { + "dataSource": "db" + }, + "AccessToken": { + "dataSource": "db", + "public": false + }, + "ACL": { + "dataSource": "db", + "public": false + }, + "RoleMapping": { + "dataSource": "db", + "public": false + }, + "Role": { + "dataSource": "db", + "public": false + }, + "CoffeeShop": { + "dataSource": "mysqlDs", + "public": true + } +} diff --git a/server/server.js b/server/server.js new file mode 100644 index 0000000..ef738ab --- /dev/null +++ b/server/server.js @@ -0,0 +1,29 @@ +'use strict'; + +var loopback = require('loopback'); +var boot = require('loopback-boot'); + +var app = module.exports = loopback(); + +app.start = function() { + // start the web server + return app.listen(function() { + app.emit('started'); + 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; + + // start the server if `$ node server.js` + if (require.main === module) + app.start(); +});