Access Polymer3.0 custom elements from static html - polymer

I created a custom Polymer3.0 element. And it works fine when I do ploymer serve.
We have an internal enterprise NPM registry, to which I published my element.
Now I want to use this element in a completely different project (which has only static HTML/JS) and is served by NGNIX server.
Is this possible ? If so how to approach it ?
Do I need to server my custom element via node or http-server for me to use in a static html in a completely different project ?
Can we server the polymer3.0 elements like CDN, I saw some posts with unpkg, but for that I need to publish to global NPM. R there any other options ?

I was able to solve the issue (in-fact it was me not looking at all the options in polymer.json).
If anyone is interested following is what I did..
In my ploymer.json I added the following
shell property of json to point to my custom element js file
I also added to the js property, "compile":true..
Following is what my polymer.json looks like
...
"shell": "xxxxx.js",
"builds":[
{
"name": "prod",
"preset": "es6-bundled",
"bundle":true,
"moduleResolution": "node",
"addServiceWorker": true,
"inlineCss": true,
"inlineScripts": true,
"rewriteUrlsInTemplates": true,
"sourcemaps": true,
"stripComments": true,
"js": {"minify":true, "compile":true},
"css": {"minify":true},
"html":{"minify":true}
},
...
I copied my files in build/ folder to my nginx server and hosted them as regular folder. Of course I add add_header Access-Control-Allow-Origin *; to my conf file
In my static HTML to import my component all I had to do is
<script src="https://unpkg.com/#webcomponents/webcomponentsjs#2.4.3/webcomponents-loader.js"></script>
<script type="module" src="http://XXX_MY_NGINX_VIRTUAL_HOST_XXXX/my-custom-element.js"></script>

Related

How to make a Chrome Extension to redirect when specific pages are accessed in Manifest V3

I'm trying to make a Chrome extension that redirects to a pre defined page when a specified page is loaded.
I'm using webRequest for this, But now that I have to migrate to Manifest V3, webRequest can not be used anymore.
Can anyone help me with rewrite the script to make it work with Manifest V3?
Here's the script that I use to redirect pages:
var host = "http://example.com";
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {redirectUrl: host + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]};
},
{
urls: [
"*://foo.com/demo*",
"*://www.foo.com/test/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);
I would not recommend using declarativeNetRequest for this task, it is very limited in its capabilities and has an awkward interface.
It sounds like you want to redirect the user prior to the page being loaded. If that's the case, you need to hook into the request/response lifecycle using chrome.debugger API. I describe how to do that here- his application seems easily adaptable to your own. This is the only way to get the same caliber request manipulation capabilities in MV3 as in MV2.
Alternative approach:
-Use the chrome.webNavigation API. This will just entail setting up event listeners/handlers for one or more of the following:
onBeforeNavigate -> onCommitted -> [onDOMContentLoaded] -> onCompleted
Here you can find many examples of other projects using this API.

Can't Define Services in CAS Overlay Template v. 6.4 (Docker)

Using the cas-overlay-template, I am trying to access the CAS login screen from HTTP(s)://localhost/admin:
https://localhost:8443/cas/login?service=https%3A%2F%2F0.0.0.0%2Fadmin
To do this, I am trying to define services inside /etc/cas/services/services.json:
{
"#class" : "org.apereo.cas.services.RegexRegisteredService",
"serviceId" : "^http://.*",
"name" : "http_services",
"allowed": true,
"ssoEnabled": true,
"anonymousAccess": false,
"id" : 1,
"evaluationOrder" : 1
},
{
"#class" : "org.apereo.cas.services.RegexRegisteredService",
"serviceId" : "^https://.*",
"name" : "https_services",
"allowed": true,
"ssoEnabled": true,
"anonymousAccess": false,
"id" : 2,
"evaluationOrder" : 2
}
FWIW, I've also tried to define a service file according to the pattern described here.
In /etc/config/cas.properties, I have defined the following:
cas.server.name=https://cas.example.org:8443
cas.server.prefix=${cas.server.name}/cas
cas.service-registry.json.location=classpath:/services
logging.config=file:/etc/cas/config/log4j2.xml
Finally in build.gradle, I have added the support for JSON service registry:
dependencies {
...
implementation "org.apereo.cas:cas-server-support-json-service-registry:${casServerVersion}"
}
No matter what I do, after building and running the Docker image, I always get the same thing:
INFO [org.apereo.cas.services.AbstractServicesManager] - <Loaded [0] service(s) from [JsonServiceRegistry].>
When I go to the URL, I am told
"Application Not Authorized to Use CAS".
What am I doing wrong?
Bonus question: https://cas.example.org:8443 does not work in the URL. Do I need to edit something in the docker container to get this to map onto my local machine?
-- UPDATE --
As was said in the answer, I needed to create a single, named service:
// File: /etc/cas/services/today-12345.json
{
"#class":"org.apereo.cas.services.RegexRegisteredService",
"serviceId":"^(https|http|imaps)://.*",
"name":"today",
"id" :12345
}
To part 2 of Misagh's answer, based on what I'm seeing in the Dockerfile, the /etc/cas/services directory simply doesn't exist by the time ./gradlew runs, and so the services aren't registered.
If I put in my cas.properties file
cas.service-registry.json.location=/etc/cas/services
I get a stacktrace that includes:
Caused by: java.io.FileNotFoundException: class path resource [etc/cas/services] cannot be resolved to URL because it does not exist
If I /bin/sh into the container, I can see the service inside of the /etc/cas/services directory.
I've been getting around this by simply copying the .json file after the Docker containers have been built
docker cp ~/emu/cas-overlay-template/etc/cas/services/today-12345.json [CONTID]:/tmp/services
(/tmp/services because that's where the console output says it's watching for services)
-- SOLUTION --
The path had to be:
cas.service-registry.json.location=file:/etc/cas/services
What am I doing wrong?
Multiple things.
You have your services in /etc/cas/services/services.json as a single JSON file. That is not correct. You need to have 1 file per 1 app. Consult the documentation for JSON service registry.
cas.service-registry.json.location should point to the directory location where such JSON files are found. You need to make sure this location in your Docker setup points or contains your service definitions.
I know I'm a bit late but I think the location /etc/cas/services it is defined in the apereo cas standalone profile. If you define another spring profile it will look for /tmp/services. It happened to me while configuring cas in docker environment and wanting to use a test profile.

Change swagger host and port serving it statically

Inspired by this sample repository, I'm generating a swagger output in json with protoc and serving it. However, for certain reasons I'm hosting the swagger content on a different port(:10000) than my REST api service(:8000).
I'm using the Go library statik to bundle up the swagger assets and serve them. It works, and a webpage is served when going to localhost:10000.
However, every cURL request swagger makes seems to be confined to just that - localhost:10000. The REST API lives on localhost:8081.
Serving swagger-ui with static content, how do I change the host/port for the REST api server?
I've tried going into the index.html of the swagger-ui content to add basePath as here, but with no luck. Every request is still made to :10000
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./service.swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
// I added this, but it did not change anything.
basePath: "localhost:8081"
})
// End Swagger UI call region
window.ui = ui}
</script>
Add host with value localhost:8081
Remove basePath, basePath is used to change the relative path after host i.e if your web server is hosted at /v1/ etc, then you can use basepath to change that
i am still trying to find out how to pass host value dynamically for production, stage, dev env

BabelHelpers is not defined using Polymer

I'm using Polymer and its build process. The bundled files are generated throughmy polymer.json file.
I'm not explicitely using Babel, I've just seen it's used by "paper-autocomplete".
When going to the website, I have a js error stating the BabelHelpers is not defined.
When I use MAJ+F5, it works !
When I use F5, it doesn't work
(BabelHelpers is not defined)
When running it locally it works fine. When I deploy it to my server, I face this issue.
I'm running it as a standalone Java application as it has a Spring backend.
The website as multiple entry points, it works fine for all other ones.
The stacktrace :
Command :
polymer build --js-minify --css-minify --html-minify
The polymer.json file
{
"entrypoint": "pt.html",
"builds": [{
"bundle": true,
"js": {"compile": true, "minify": true},
"css": {"minify": true},
"html": {"minify": false},
"addServiceWorker": true
}],
"shell": "resources/elements-platform.html",
"fragments": [
"resources/html/lazy-resources.html",
"resources/html/ym-dashboard.html",
"resources/html/ym-partners.html",
"resources/html/ym-favorite.html",
"resources/html/ym-agenda.html",
"resources/html/ym-todos.html",
"resources/html/ym-profile.html",
"resources/html/ym-messages.html",
"resources/html/shop-list.html",
"resources/html/shop-detail.html"
],
"sources": [
"resources/src/**/*",
"resources/css/**/*",
"resources/data/**/*",
"resources/images/**/*",
"resources/img/**/*",
"resources/js/*",
"resources/js/cal/*",
"resources/js/countdown/*",
"resources/bower.json"
],
"extraDependencies": [
"resources/bower_components/webcomponentsjs/webcomponents-lite.min.js"
]
}
I run into the same issue few days ago after I updated Polymer-cli to newest version. But in my case my application throwed same error on local virtual host (with self-sign certificate). On production website it was fine.
Actually, babelHelpers are injected into file that is selected as entrypoint inside your polymer.json file. Maybe try to look there, if you have correct existing file.
there are few existing issues on github with this problem. Unfortunately there is no verified answer (Polymer team does not really care about github issues)
https://github.com/Polymer/polymer-cli/issues/787
https://github.com/Polymer/polymer-cli/issues/765
There is also same question on stackoverflow with answer:
polymer-cli - getting "Can’t find variable: babelHelpers" when I set compile to true
I too am seeing 'babelHelpers' is undefined. In my case it's coming from redux.js:
q='object'==('undefined'===typeof self?'undefined':babelHelpers
.typeof(self))&&self&&self.Object===Object&&self,r=p||q||
Function('return this')(),s=r.Symbol,t=Object.prototype,
Babel helpers is also raised as in Issue #606, which says that it's resolved and closed. But it or something similar is back.
I made a few changes, but I don't know which one solved the issue. The problem came from paper-autocomplete. When I stopped using it I didn't have the issue anymore.
I'm still using it, but I made several changes :
I made sure I was using the generated service-worker
I stopped using the version of JQuery that was in my bower (3.2.1) and used it from JQuery CDN (2.3.1) as I've seen it caused issues sometimes
Added manifest.json in the polymer.json file

Chrome doesn’t show un-minified code in spite of source map present

I’m using Grunt and UglifyJS to generate source maps for my AngularJS app. It produces a file customDomain.js and customDomain.js.map.
JS file
Last line of customDomain.js looks like this:
//# sourceMappingURL=customDomain.js.map
Map file
I find two references to customDomain.js inside of customDomain.js.map, one at the beginning:
"sources":["../../../.tmp/concat/scripts/customDomain.js"]
I think this looks weird so I trim it to:
"sources":["customDomain.js"]
The second reference is at the end:
"file":"customDomain.js"
...which I leave as it is.
Testing
When I run my app in Chrome I expect to see my development code when I click on customDomain.js, but I do not:
I can see on the console output from my web server that customDomain.js.map is indeed requested from the browser:
200 /js/customDomain.js.map (gzip)
What is missing?
"sources":["customDomain.js"] should be relative to the customDomain.map.js file.
Make sure they are in the same directory on your server if this is the case for you.
"file":"customDomain.js" should be changed to the name of the map file, in your case this would be "file":"customDomain.map.js".
Here's a map file example taken from treehouse (sourceRoot may be unnecessary in your case):
{
version: 3,
file: "script.js.map",
sources: [
"app.js",
"content.js",
"widget.js"
],
sourceRoot: "/",
names: ["slideUp", "slideDown", "save"],
mappings: "AAA0B,kBAAhBA,QAAOC,SACjBD,OAAOC,OAAO..."
}