CORS en servidor express, cargador de rutas

This commit is contained in:
Juan Ferrer Toribio 2016-10-06 15:32:03 +02:00
parent d94bfa0adc
commit 86a19c47ee
10 changed files with 45 additions and 16 deletions

View File

@ -2,5 +2,4 @@ import {bootstrap} from './bootstrap';
import * as spliting from './spliting';
import * as routes from './routes';
bootstrap();

View File

@ -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) {
});
}
}
})
})
});

View File

@ -1,4 +0,0 @@
{
"route": "buys",
"template": "buys.template"
}

View File

@ -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'
export {NAME as LABELBT,factory as labelbt} from './label/label.bt'

View File

@ -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 ())

View File

@ -1,4 +0,0 @@
{
"route": "sales",
"template": "sales.template"
}

View File

@ -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'));
});

View File

@ -11,6 +11,11 @@
<a ui-sref="edit">edit</a>
<a ui-sref="delete">delete</a>
</div>
<script type="text/javascript" src="build/salix.app.js" selector="#app"></script>
<script
type="text/javascript"
src="build/salix.app.js"
selector="#app"
routes-cdn="http://localhost:8080/routes">
</script>
</body>
</html>

View File

@ -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"

View File

@ -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);