Skip to content

Commit

Permalink
feat(cli): Allow to configure access origin tags on cordova config.xml (
Browse files Browse the repository at this point in the history
#5134)


Co-authored-by: Marc Rominger <marc.rominger@transporeon.com>
Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
3 people authored Oct 27, 2021
1 parent 31ec30d commit 0841a09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cli/src/cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ export async function autoGenerateConfig(
}
});

let accessOriginString: string[] = [];
if (config.app.extConfig?.cordova?.accessOrigins) {
accessOriginString = await Promise.all(
config.app.extConfig.cordova.accessOrigins.map(
async (host): Promise<string> => {
return `
<access origin="${host}" />`;
},
),
);
} else {
accessOriginString.push(`<access origin="*" />`);
}
const pluginEntriesString: string[] = await Promise.all(
pluginEntries.map(async (item): Promise<string> => {
const xmlString = await writeXML(item);
Expand All @@ -268,7 +281,7 @@ export async function autoGenerateConfig(
}
const content = `<?xml version='1.0' encoding='utf-8'?>
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" />
${accessOriginString.join('')}
${pluginEntriesString.join('')}
${pluginPreferencesString.join('')}
</widget>`;
Expand Down
10 changes: 10 additions & 0 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,16 @@ export interface CapacitorConfig {
};

cordova?: {
/**
* Populates <access> tags in the config.xml with the origin set to
* the values entered here.
* If not provided, a single <access origin="*" /> tag gets included.
* It only has effect on a few Cordova plugins that respect the whitelist.
*
* @since 3.3.0
*/
accessOrigins?: string[];

/**
* Configure Cordova preferences.
*
Expand Down

0 comments on commit 0841a09

Please sign in to comment.