From 86a19c47ee265f8284813a742090c300742e5e7c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 6 Oct 2016 15:32:03 +0200 Subject: [PATCH] CORS en servidor express, cargador de rutas --- @salix/app/src/app.js | 1 - @salix/app/src/routes.js | 3 +-- @salix/compras/routing.json | 4 ---- @salix/core/src/core.js | 5 ++++- @salix/core/src/routesLoader.js | 29 +++++++++++++++++++++++++++++ @salix/ventas/routing.json | 4 ---- gulpfile.js | 2 +- index.html | 7 ++++++- package.json | 1 + server.js | 5 +++-- 10 files changed, 45 insertions(+), 16 deletions(-) delete mode 100644 @salix/compras/routing.json create mode 100644 @salix/core/src/routesLoader.js delete mode 100644 @salix/ventas/routing.json diff --git a/@salix/app/src/app.js b/@salix/app/src/app.js index 6f2c434cc..b3ac02fdd 100644 --- a/@salix/app/src/app.js +++ b/@salix/app/src/app.js @@ -2,5 +2,4 @@ import {bootstrap} from './bootstrap'; import * as spliting from './spliting'; import * as routes from './routes'; - bootstrap(); diff --git a/@salix/app/src/routes.js b/@salix/app/src/routes.js index 4259fcd63..bd9961173 100644 --- a/@salix/app/src/routes.js +++ b/@salix/app/src/routes.js @@ -1,7 +1,6 @@ import * as core from '@salix/core'; import * as spliting from './spliting'; - core.module.config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/"); @@ -17,5 +16,5 @@ core.module.config(function($stateProvider, $urlRouterProvider) { }); } } - }) + }) }); diff --git a/@salix/compras/routing.json b/@salix/compras/routing.json deleted file mode 100644 index ac6307544..000000000 --- a/@salix/compras/routing.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "route": "buys", - "template": "buys.template" -} diff --git a/@salix/core/src/core.js b/@salix/core/src/core.js index 244e3735a..d6049004e 100644 --- a/@salix/core/src/core.js +++ b/@salix/core/src/core.js @@ -3,8 +3,11 @@ */ export * from './module'; export * from './util'; + export {NAME as RESOLVEDEFAULTCOMPONENT, ResolveDefaultComponent} from './resolveDefaultComponents' export {NAME as INTERPOLATE,Interpolate} from './interpolate' +export {NAME as ROUTESLOADER, RoutesLoader} from './routesLoader' + export {NAME as BUTTON,directive as ButtonDirective} from './button/button' export {NAME as BUTTONMT,factory as buttonmt} from './button/button.mt' export {NAME as BUTTONBT,factory as buttonbt} from './button/button.bt' @@ -19,4 +22,4 @@ export {NAME as TEXTFIELDMT,factory as textfieldmt} from './textfield/textfield. export {NAME as TEXTFIELDBT,factory as textfieldbt} from './textfield/textfield.bt' export {NAME as LABEL,directive as LabelDirective} from './label/label' export {NAME as LABELMT,factory as labelmt} from './label/label.mt' -export {NAME as LABELBT,factory as labelbt} from './label/label.bt' \ No newline at end of file +export {NAME as LABELBT,factory as labelbt} from './label/label.bt' diff --git a/@salix/core/src/routesLoader.js b/@salix/core/src/routesLoader.js new file mode 100644 index 000000000..9fb665721 --- /dev/null +++ b/@salix/core/src/routesLoader.js @@ -0,0 +1,29 @@ + +import {module as _module} from './module' +import * as util from './util' + +export const NAME = util.getProviderName ('RoutesLoader') + +export class RoutesLoader +{ + constructor () {} + + $get ($http) + { + let script = document.currentScript || (() => { + let scripts = document.getElementsByTagName ('script'); + return scripts[scripts.length - 1]; + }) (); + + let routesCdn = script.getAttribute ('routes-cdn'); + + return $http + ({ + method: 'GET', + url: routesCdn + }) + } +} + +_module.provider (NAME, () => new RoutesLoader ()) + diff --git a/@salix/ventas/routing.json b/@salix/ventas/routing.json deleted file mode 100644 index ef776755e..000000000 --- a/@salix/ventas/routing.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "route": "sales", - "template": "sales.template" -} diff --git a/gulpfile.js b/gulpfile.js index 6fbf8aebc..eecadce9c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,7 @@ function combineFunc (data) gulp.task ('default', function () { - var json = gulp.src ('./@salix/**/routing.json') + var json = gulp.src ('./@salix/**/routes.json') .pipe (jsoncombine ('salix.routes.json', combineFunc)) .pipe (gulp.dest ('./build')); }); diff --git a/index.html b/index.html index b506e8e60..e9699e82c 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,11 @@ edit delete - + diff --git a/package.json b/package.json index df20f4e4b..8cc3727e6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "angular": "^1.5.8", "angular-ui-router": "^1.0.0-beta.3", + "cors": "^2.8.1", "express": "^4.14.0", "material-design-lite": "^1.2.1", "oclazyload": "^0.6.3" diff --git a/server.js b/server.js index cee4df2ea..e5a13d32c 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ var express = require ('express'); +var cors = require ('cors'); function getRoutes (req, res) { @@ -18,7 +19,7 @@ function onListen () } var app = express (); -app.get ('/routes.json', getRoutes); -app.all (/.*/, getDefault); +app.get ('/routes', cors (), getRoutes); +app.all (/.*/, cors (), getDefault); app.listen (8080, onListen);