Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
rbartley2
Contributor
Contributor

Enigma.js in mashup - issues with loading schema

Hi everyone,

 

I am trying to use enigma.js to access the Engine API from within a mashup, but am having an issue when trying to specify the schema.

Following the instructions from here https://github.com/qlik-oss/enigma.js/blob/master/docs/api.md#enigmacreateconfig,

I add the line: 

 

const schema = require('../enigma/schemas/12.170.2.json');

 

 but I get an error message in the console:

 

enigma schema error.JPG

I know that the json file is accessible as I can access it directly through my browser, so does anyone have any ideas?

 

Thanks in advance.

 

 

Labels (2)
1 Solution

Accepted Solutions
ErikWetterberg

If you are using requirejs you need to make sure you wait unitil the json file is loaded. Assuming you already have a require call off the format:

require([....], function( x, a y){

    //lots of code here

});

you could add the schema to the dependency array.

You could also use fetch:

    then(response => response.json()).
    then(schema => 

View solution in original post

4 Replies
han
Employee
Employee

You are using a relative path in your require ('../enigma....)

That would reference from your javascript file that defining the require

Try using a reference to the enigma.js module instead

'enigma.js/schemas/12.170.2.json'

 

rbartley2
Contributor
Contributor
Author

Hi,

 

Thanks for responding.  Unfortunately, I get a similar message (only the reference is different):

enigma schema error2.JPG

ErikWetterberg

If you are using requirejs you need to make sure you wait unitil the json file is loaded. Assuming you already have a require call off the format:

require([....], function( x, a y){

    //lots of code here

});

you could add the schema to the dependency array.

You could also use fetch:

    then(response => response.json()).
    then(schema => 
rbartley2
Contributor
Contributor
Author

Hi Erik,

 

Thanks for this. fetch() worked for me and I can now use Enigma.js to open an app.  For anyone interested, here's the code I used.  I will continue to work on this to fulfil my requirement.

 

$( document ).ready(function()
{
	...
	...
	 
	 var config = {
					host:window.location.hostname,
					port: 82
					};
	require.config( {
						baseUrl: (config.isSecure ? "https://" : "http://" ) + config.host + (config.port ? ":" + config.port : "" ) + config.prefix
					} );
	
	
	schemaLocation = "http://"+config.host + (config.port ? ":" + config.port : "" )+"/enigma/schemas/12.170.2.json";
	console.log('schemaLocation',schemaLocation);
	fetch(schemaLocation).then(response => response.json()).then(function(schema)
	{
		
		prefix = window.location.pathname.substr( 0, window.location.pathname.toLowerCase().lastIndexOf( "/extensions" ) + 1 );
	
		var config = {
					host: window.location.hostname,
					prefix: prefix,
					port: 82,
					isSecure: window.location.protocol === "https:"
					,identity:strIdentity
			};
			
			require.config( {
				baseUrl: (config.isSecure ? "https://" : "http://" ) + config.host + (config.port ? ":" + config.port : "" ) + config.prefix
			} );
		
		require(['enigma/enigma'],function(enigma)
		{
			
			var config = {
					host: window.location.hostname,
					prefix: prefix,
					port: window.location.port,
					isSecure: window.location.protocol === "https:"
					,identity:strIdentity
			};
			
			require.config( {
				baseUrl: (config.isSecure ? "https://" : "http://" ) + config.host + (config.port ? ":" + config.port : "" ) + config.prefix + "resources"
			} );
			
			require( ['js/qlik'], function ( qlik ) 
			{
				var config = {
					  schema: schema,
					  url: 'ws://s-agri-qaptest1/app/engineData',
					   createSocket: url => new WebSocket(url),
					  suspendOnClose: true,
					  protocol: { delta: false },
					};
				
				
				const session = enigma.create(config).open().then(function(global)
				{
					var app = qlik.openApp('4d791990-c8c5-4766-b5ea-e73d36ef7358',config);
				});
			});
		});	
	});
	
});