Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Présentation Sails @ SupInfo
Search
Sylvain PONTOREAU
March 26, 2014
Technology
0
91
Présentation Sails @ SupInfo
Présentation générale du framework
Sylvain PONTOREAU
March 26, 2014
Tweet
Share
More Decks by Sylvain PONTOREAU
See All by Sylvain PONTOREAU
aMS Lausanne - Préparez-vous à une virée intersidérale avec Azure Cosmos DB 🧑🚀
spontoreau
0
4
TypeScript - 45 minutes pour s’y mettre !
spontoreau
0
78
Event Sourcing avec Azure, quelle base de données choisir
spontoreau
0
21
Decorators in TypeScript 5.0, everything you need to know!
spontoreau
0
350
Leverage your CI/CD at the next level with Github actions
spontoreau
0
8
Commit comme un(e) "Hipster" avec Gitmoji !
spontoreau
0
93
Bird of a Feather - TypeScript (Devoxx 2022)
spontoreau
0
16
GitHub - Du besoin jusqu'à la production avec Github et Azure
spontoreau
0
15
Behavior Driven Development
spontoreau
1
200
Other Decks in Technology
See All in Technology
プロトタイピングによる不確実性の低減 / Reducing Uncertainty through Prototyping
ohbarye
5
380
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
120
非同期推論システムによるコスト削減と信頼性向上
koki_nishihara
0
240
Janus
bkuhlmann
1
490
ChatGPT for IT Service Management (IT Pro)
dahatake
7
1.6k
Compose Compiler Metricsを使った実践的なコードレビュー
tomorrowkey
1
220
20分で完全に理解するGrafanaダッシュボード
hamadakoji
3
520
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
460
オーナーシップを持つ領域を明確にする
konifar
13
3.1k
Além do else! Categorizando Pokemóns com Pattern Matching no JavaScript
wmsbill
0
600
Next'24 事例セッションの紹介とクラウド資格を活用したキャリア形成について語りMuscle
yasumuusan
1
440
ここが嬉しいABAC ここが辛いよABAC #再解説+補足編
masahirokawahara
1
270
Featured
See All Featured
How to Ace a Technical Interview
jacobian
272
22k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
125
32k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
Practical Orchestrator
shlominoach
182
9.7k
Product Roadmaps are Hard
iamctodd
44
9.7k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
Fireside Chat
paigeccino
21
2.6k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.6k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Debugging Ruby Performance
tmm1
70
11k
Transcript
Sails : Framework MVC pour Node.js 26 Mars 2014 -
Sup’Info Montparnasse - Sylvain PONTOREAU
Sommaire 1 - Rappel sur Node 2 - Solutions MVC
pour Node.js 4 - Sails in action 3 - Présentation de Sails 5 - Conclusion
1 - Piqure de rappel sur… … Node.js ! -
Mono-Thread asynchrone piloté par event - JavaScript (Harmony features) - Google V8 - Module HTTP - Node Package Module
2 - Les Stacks MVC … … et leur popularité
! 1.5k 2.4k 5.5k 12k Meteor Kraken
3 - Présentation de … … Sails.js ! - Conçu
par et pour les développeurs - Orienté application d’entreprise - Affinité pour les données - Inspiré par Ruby on Rails - Idéal pour les applications temps réel
3 – Caractéristiques … … techniques ! - Convention over
Configuration - Stack RoR Like - Automatic Rest Back-end - ORM inside (Waterline) - Database Adapter - Action sur requête HTTP et WebSocket - Gestion des accès - Asset bundling - Sails CLI
3 – Qu’y a-t-il … … dans le stack !
Waterline Grunt Windson
4 - Sails in … … action ! Installation npm
install sails -g Créer un projet sails new myNewProject cd myNewProject npm update Lancer l’application sails lift
4 - Définition d’un … … modèle ! sails generate
person Person.js : module.exports = { attributes : { } }; attributes: { name : 'STRING', age : { type : 'INTEGER', required : true }, birthDate : 'DATE' } Types disponibles : string, text, integer, float, date, time, datetime, boolean, binary, array, json Validateurs disponibles : empty, required, email, url, ip, notNull, regex, contains, minLength, maxLength …
4 – Configuration … … des adapters Waterline ! npm
install sails-mongo --save config/adapter.js : module.exports.adapters = { default : 'mongo', mongo : { module : 'sails-mongo', host : 'localhost', port : 27017, user : 'username', password : 'password', database : 'Person' } };
4 – Automatic … … Rest Backend ! Requête POST
valide => { "name" : "sylvain", "age" : "30" , "birthDate" : “05/28/1983" } Response : { "name": "sylvain", "age": 30, "birthDate": "05/28/1983", "createdAt": "2014-03-24T10:11:46.358Z", "updatedAt": "2014-03-24T10:11:46.358Z", "id": "533004e24510daf41d7de305" } Requête POST non valide => { "name" : "sylvain", "age" : “30" , "birthDate" : “pasundate" } Response : { "status": 500, "errors": [{ "ValidationError": { "birthDate": [ { "data": "pasundate", "message": "Validation error: \"pasundate\" is not of type \"date\"", "rule": "date" }] } } ] }
4 – Automatic … … Rest Backend ! Requête GET
=> http://localhost:1337/Person Response : [ { "name": "sylvain", "age": 30, "birthDate": "05/28/1983", "createdAt": "2014-03-24T10:11:46.358Z", "updatedAt": "2014-03-24T10:11:46.358Z", "id": "533004e24510daf41d7de305" }, { "name": "bill", "age": 58, "birthDate": "10/28/1955", "createdAt": "2014-03-24T10:29:45.131Z", "updatedAt": "2014-03-24T10:29:45.131Z", "id": "533009194510daf41d7de306" }, … ] Requête GET => http://localhost:1337/Person?name=sylvain Response : { "name": "sylvain", "age": 30, "birthDate": "05/28/1983", "createdAt": "2014-03-24T10:11:46.358Z", "updatedAt": "2014-03-24T10:11:46.358Z", "id": "533004e24510daf41d7de305" }
4 - Socket.io … … inside ! Test dans chrome
:
4 - Création d’un contrôleur … et ses actions !
PersonController.js : module.exports = { _config: {} }; module.exports = { getAll : function(req, res){ Person.find().exec(function(err, data){ res.render('person/getAll', {persons : data}) }); }, _config: {} }; config/routes.js : module.exports.routes = { '/': { view: 'home/index' }, '/persons' : { controller : 'PersonController', action : 'getAll' } }; sails generate person
4 - Les vues … … avec EJS ! views/layout.ejs
: <!DOCTYPE html> <html> <head> <title><%- title %></title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> </head> <body> <%- body %> <script type="text/javascript" src="/js/socket.io.js"></script> <script type="text/javascript" src="/js/sails.io.js"></script> <script type="text/javascript" src="/js/app.js"></script> </body> </html> views/person/getAll.ejs : <ul> <% for(var i=0; i < persons.length; i++) {%> <li> <%= persons[i].name %> - <%= persons[i].age %> - <%= persons[i].birthDate %> </li> <% } %> </ul>
4 – Policies … … et contrôle des accès !
api/policies/isAuthenticated.js : module.exports = function(req, res, next) { if (req.session.authenticated) { return next(); } return res.forbidden('You are not permitted to perform this action.'); }; config/policies.js : module.exports.policies = { //'*': true, PersonController: { '*': false, getAll : 'isAuthenticated', otherFunction : ['isAuthenticated', 'isAdmin'] } };
4 – Grunt … … et l’asset bundling gruntfile.js :
module.exports = function (grunt) { grunt.initConfig({ concat : { dist : { src : 'asserts/js/*.js', dest : 'asserts/js/myApp.js' } }, uglify : { dist : { src : '<%= concat.dist.dest %>', dest : 'public/js/myApp.min.js' } } }); … } gruntfile.js : grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.registerTask('default', ['concat' , 'uglify' ]); grunt
5 – Conclusion … - Un Framework MVC efficace -
Nombreuses features out of the box - ORM adaptable - Développement de Backend in no time ! - Essayez le ! … le poulpe c’est bon, mangez en !
Merci… 26 Mars 2014 - Sup’Info Montparnasse - Sylvain PONTOREAU
… à tous et bon pot ! Source disponible sur GitHub ! https://github.com/Vtek/SailsDCubeExemple