@quatico/magellan-client v0.14.2
Transport configuration
Magellan uses the global.qsMagellanConfig object to access transport configurations at runtime.
{
"namespaces": {
"default": {
"endpoint": "/api",
"transport": "default"
}
}
}This configuration is injected to the window object by @quatico/magellan-client/lib/transport/config.js which can
be replaced during bundling with Webpack to invoke a request against a my-api endpoint, merging its transport
configuration if another magellan-client based frontend was already loaded previously.
magellan.config.js
const createFormData = ({name, payload, namespace}) => {
const formData = new FormData();
formData.set("name", name);
formData.set("data", payload);
formData.set("namespace", namespace);
return formData;
};
// func is of type @quatico/magellan-client TransportFunction
const myTransportFunction = async func => {
const {name, payload, namespace, endpoint} = func;
if (!name) {
throw new Error('Cannot invoke this remote function without "name" property.');
}
try {
const response = await fetch(endpoint, {
method: "POST",
body: createFormData({name, payload, namespace}),
});
return await response.text();
} catch (err) {
throw new Error(`Cannot invoke remote function: "${name}". Reason: "${err}".`);
}
};
module.exports = {
namespaces: {"test-namespace": {endpoint: "/my-api", transport: "my-transport"}},
transports: {"my-transport": myTransportFunction},
merge: true
};webpack.config.js
plugins: [
new webpack.NormalModuleReplacementPlugin(
/@quatico[\\/]magellan-client[\\/]lib[\\/]transport[\\/]config.js/,
path.join(__dirname, "magellan.config.js")
),
]1 year ago
11 months ago
1 year ago
10 months ago
1 year ago
9 months ago
10 months ago
1 year ago
9 months ago
8 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago