opencomponents/oc

Ability to override 'https://unpkg.com` domain at repository for templates.js

kmcrawford opened this issue · 2 comments

Who is the bug affecting?

Consumers of OC, we would like to host unpkg.com react libraries on our domain so we minimize the number of domains, and control access. unpkg.com is blocking Google Bots for some libraries and thus can effect SEO.

What is affected by this bug?

Browser client

When does this occur?

When templates.js has a reference to unpkg.com

Where on the platform does it happen?

Client, server-side rendered.

How do we replicate the issue?

Publish a react component and set your user-agent to Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) you will see a 403.

Expected behavior (i.e. solution)

Let the registry decide to allow to override the domain with a custom property for domain/path.

What version of OC, Node.js and OS are you using?

Not applicable

Resolved.

In addition to this change to override unpkg.com for client side rendering, the following must also be done in your registry startup.


const ocTemplateReact = require("oc-template-react");
const myTemplate = {
  type: ocTemplateReact.getInfo().type,
  version: ocTemplateReact.getInfo().version,
  externals: [
    {
      "name": "Object.assign",
      "global": [
        "Object",
        "assign"
      ],
      "url": "https://mydomain.com/es6-object-assign@1.1.0/dist/object-assign-auto.min.js"
    },
    {
      "name": "prop-types",
      "global": "PropTypes",
      "url": "https://mydomain.com/prop-types@15.7.2/prop-types.min.js"
    },
    {
      "name": "react",
      "global": "React",
      "url": "https://mydomain.com/react@16.9.0/umd/react.production.min.js"
    },
    {
      "name": "react-dom",
      "global": "ReactDOM",
      "url": "https://mydomain.com/react-dom@16.9.0/umd/react-dom.production.min.js"
    }
  ]
}
const myTemplateReact = {
  getCompiledTemplate: ocTemplateReact.getCompiledTemplate,
  render: ocTemplateReact.render,
  getInfo: () => myTemplate
}

//in configuration 
templates: [myTemplateReact],