Un breve ejemplo de uso CORS AEM para acceder a contenido de la desde una aplicación web externa a través de JavaScript del lado del cliente.
En este vídeo:
/etc/hosts
/etc/hosts
aem-publish.local
hasta localhost:4503
.Para obtener más información, consulte AEM Comprender el Intercambio de Recursos de Origen Cruzado (CORS) en la.
Esta página web tiene una lógica que
http://aem-publish.local/content/we-retail/.../experience/_jcr_content.1.json
jcr:title
de la respuesta JSONjcr:title
en el DOM<html>
<head>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body style="width: 960px; margin: 2rem auto; font-size: 2rem;">
<button style="font-size: 2rem;"
data="fn-getTitle">Get Title as JSON from AEM</button>
<pre id="title">The page title AJAX'd in from AEM will injected here</pre>
<script>
$(function() {
/** Get Title as JSON **/
$('body').on('click', '[data="fn-getTitle"]', function(e) {
$.get('http://aem-publish.local/content/we-retail/us/en/experience/_jcr_content.1.json', function(data) {
$('#title').text(data['jcr:title']);
},'json');
e.preventDefault();
return false;
});
});
</script>
</body>
</html>
La fábrica de configuración de OSGi para Cross-Origin Resource Sharing está disponible mediante:
http://<host>:<port>/system/console/configMgr > Adobe Granite Cross-Origin Resource Sharing Policy
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
alloworigin="[https://www.example.com:8000]"
alloworiginregexp="[]"
allowedpaths="[/content/we-retail/.*]"
exposedheaders="[]"
maxage="{Long}1800"
supportedheaders="[Origin,Accept,X-Requested-With,Content-Type,
Access-Control-Request-Method,Access-Control-Request-Headers]"
supportedmethods="[GET]"
supportscredentials="{Boolean}false"
/>
Para permitir el almacenamiento en caché y el servicio de encabezados CORS en contenido almacenado en caché, agregue lo siguiente Configuración de /clientheaders a todos los que admitan AEM Publish dispatcher.any
archivos.
/myfarm {
...
/clientheaders {
"Access-Control-Allow-Origin"
"Access-Control-Expose-Headers"
"Access-Control-Max-Age"
"Access-Control-Allow-Credentials"
"Access-Control-Allow-Methods"
"Access-Control-Allow-Headers"
}
...
}
Reinicie la aplicación del servidor web después de realizar cambios en el dispatcher.any
archivo.
Es probable que se necesite borrar la caché por completo para garantizar que los encabezados se almacenen correctamente en la caché en la siguiente solicitud después de un /clientheaders
actualización de configuración.
Python SimpleHTTPServer (Compatible con Windows/macOS/Linux)
AEM Comprender el Intercambio de Recursos de Origen Cruzado (CORS) en la