A sample Sails and Angular 2 product prototype
To run this you will need typescript compiler and npm/node installed and setup.
npm install typescript -g
npm install typings -g
npm install
typings install
tsc
npm start
browse to http://localhost:1337
It is not necessary to setup a database, this prototype uses a "localDiskDb". (./.tmp/localDiskDb.db) But if you want to test this with a "real" database configure your connection at ./config/connections.js and change the connection attribute value at ./config/models.js to the name of your previously configured connection.
Frontend code is located at ./assets/app
Backend code is almost non existent, as Sails.js provides automatic blueprints for CRUD (which this prototype utilizes).
But if you feel curious you can uncomment ./api/controllers/ProductController.js and restart the server to see my code in action.
Backend Validation is done by waterline (Sails default ORM) and the validation rules are in the model: ./api/models/Product.js
./config/bootstrap.js takes care of adding 5 dummy products while starting the server. The database is cleared on every server start, if this is not wanted, change the migrate attribute value at ./config/models.js to 'alter'
npm start
starts grunt which copies the transpiled ES5 code to ./.tmp/public/
curl -XGET 'localhost:1337/api/product'
curl -XGET 'localhost:1337/api/product?sort=currency%20ASC'
curl -XGET 'localhost:1337/api/product?sort=price%20DESC'
curl -XGET 'localhost:1337/api/product?sort=name%20ASC'
curl -G -XGET 'localhost:1337/api/product' --data-urlencode 'where={"name":{"startsWith":"G"}}'
curl -G -XGET 'localhost:1337/api/product' --data-urlencode 'where={"price":{">":"30000"}}'
curl -XGET 'localhost:1337/api/product/1'
...
- sails.js as MVC framework
- waterline as ORM
- sails-disk as adapter for waterline
- ng2-search-filter for search filter
- ng2-validation for frontend validation
- Faker.js for dummy data generation
- gruntjs for building