diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..144d51b330 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible Node.js debug attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Iniciar programa", + "program": "${workspaceRoot}/@salix-services/app/server/server.js", + "cwd": "${workspaceRoot}" + }, + { + "type": "node", + "request": "attach", + "name": "Asociar al proceso", + "port": 5858 + } + ] +} \ No newline at end of file diff --git a/@salix-services/app/client/index.ejs b/@salix-services/app/client/index.ejs new file mode 100644 index 0000000000..3324817d3f --- /dev/null +++ b/@salix-services/app/client/index.ejs @@ -0,0 +1,9 @@ + +
+Párrafo de ejemplo
+ + \ No newline at end of file diff --git a/@salix-services/app/server/boot/root.js b/@salix-services/app/server/boot/root.js index 6adce90ad3..35ea9d5743 100644 --- a/@salix-services/app/server/boot/root.js +++ b/@salix-services/app/server/boot/root.js @@ -3,6 +3,6 @@ module.exports = function(server) { // Install a `/` route that returns server status var router = server.loopback.Router(); - router.get('/', server.loopback.status()); + router.get('/status', server.loopback.status()); server.use(router); }; diff --git a/@salix-services/app/server/boot/routes.js b/@salix-services/app/server/boot/routes.js index ce898ee387..770ca1cc86 100644 --- a/@salix-services/app/server/boot/routes.js +++ b/@salix-services/app/server/boot/routes.js @@ -1,18 +1,40 @@ -/*module.exports = function(app) { +module.exports = function(app) { - var uid = require('uid2'); - // Install a "/ping" route that returns "pong" - app.get('/login', function(req, res) { - var uid(64,function(){ + app.get('/',function(req,res){ - }); - var token = req.query.access_token; - if (token) { - return res.redirect('/'); + if (req.cookies['salix-session']){ + res.render('index.ejs'); } - else { - return res.redirect('/login'); + else{ + res.status(401); + res.send("No autorizado"); } }); + //https://github.com/expressjs/cookie-parser + app.get('/login', function(req, res) { + + var token = req.query.access_token; + if (token) { + res.cookie('salix-session', token, { httpOnly: true }); + res.redirect('/'); + } + else { + res.redirect('/login1'); + } + }); + + app.get('/config.js',(req,res)=>{ + + if (req.cookies['salix-session']){ + res.set('Content-Type', 'application/json'); + //TODO: construir js dinamico de las rutas + res.status(404); + res.send(); + } + else{ + res.status(401); + res.send("No autorizado"); + } + }); + }; -*/ \ No newline at end of file diff --git a/@salix-services/app/server/datasources.json b/@salix-services/app/server/datasources.json index 0967ef424b..80b76b0b76 100644 --- a/@salix-services/app/server/datasources.json +++ b/@salix-services/app/server/datasources.json @@ -1 +1,6 @@ -{} +{ + "db": { + "name": "db", + "connector": "memory" + } +} \ No newline at end of file diff --git a/@salix-services/app/server/middleware.json b/@salix-services/app/server/middleware.json index fbfff8165d..f9de451fcb 100644 --- a/@salix-services/app/server/middleware.json +++ b/@salix-services/app/server/middleware.json @@ -32,7 +32,9 @@ }, "session": {}, "auth": {}, - "parse": {}, + "parse": { + "loopback#cookieParser":{} + }, "routes": { "loopback#rest": { "paths": [ diff --git a/@salix-services/app/server/model-config.json b/@salix-services/app/server/model-config.json index 56f6800afa..c037e528c9 100644 --- a/@salix-services/app/server/model-config.json +++ b/@salix-services/app/server/model-config.json @@ -12,5 +12,10 @@ "../common/mixins", "./mixins" ] + }, + "AccessToken": { + "dataSource": "db", + "public": false } + } diff --git a/@salix-services/app/server/server.js b/@salix-services/app/server/server.js index ef738abce2..faf411f7d1 100644 --- a/@salix-services/app/server/server.js +++ b/@salix-services/app/server/server.js @@ -2,9 +2,15 @@ var loopback = require('loopback'); var boot = require('loopback-boot'); +var path = require('path'); +//var cookieParser = require('cookie-parser'); var app = module.exports = loopback(); +app.set('view engine', 'ejs'); +app.set('views',path.join(__dirname,'../client')); +app.use(loopback.static(path.resolve(__dirname, '../client'))); + app.start = function() { // start the web server return app.listen(function() {