I'm using sw-precache in a jekyll website to add offline capabilities with the following configuration:
gulp.task('generate-service-worker', function(cb) {
var path = require('path');
var swPrecache = require('sw-precache');
var rootDir = '_site';
var packageJson = require('./package.json');
swPrecache.write('./service-worker.js', {
staticFileGlobs: [rootDir + '/**/*.{html,css,png,jpg,gif,svg}', rootDir + '/js/*'],
stripPrefix: rootDir + '/',
runtimeCaching: [{
urlPattern: /\/$/,
handler: 'networkOnly'
}],
handleFetch: argv.cacheAssets || false,
maximumFileSizeToCacheInBytes: 10485760, // 10 mb
cacheId: packageJson.name + '-v' + packageJson.version
}, cb);
});
The problem is that, when I change content in the website (for example, text in a blog post, or some text from the index page) the changes won't be shown until the new serviceworker version has been installed and the browser has been refreshed, which of course, is the expected behaviour of cacheFirst.
What I want is to make the request to the index of the site always network first, which is what I'm trying here:
runtimeCaching: [{
urlPattern: /\/$/,
handler: 'networkFirst'
}]
But this isn't working, the index is always getting fetch from the serviceworker and not from network, how can I accomplish this?
My problem is that I was including the actual page contents for precache: '/**/*.{html,css,png,jpg,gif,svg}'.
Excluding the html files works as expected:
'/**/*.{css,png,jpg,gif,svg}'
Change the url pattern to
urlPattern: "'/'"
This is a exact match pattern. Your index will match to this and nothing else.
The solution for this is, treat your index.html as dynamic content.
Change you sw webpack config to
new SWPrecacheWebpackPlugin({
cacheId: 'yourcacheid',
filename: 'service-worker.js',
staticFileGlobs: [
'dist/**/*.{js,css}'
],
minify: true,
stripPrefix: 'dist/',
runtimeCaching: [{
urlPattern: /\/$/,
handler: 'networkFirst'
}]
})
Remove your index.html from staticFileGlobs and add you root index to runtime caching.
Then look at your cache storage. You will see something like $$$toolbox-cache$$$https://your-domain.com as a new cache item. Inspect that and you can see your index cached there.
Related
I saw in the swagger ui documentation that you can provide a urls parameter which is:
An array of API definition objects ({url: "", name: ""}) used by Topbar plugin. When used and Topbar plugin is enabled, the url parameter will not be parsed. Names and URLs must be unique among all items in this array, since they're used as identifiers.
I was hoping that this will give me a selector from which I can chose which of my yaml files to process. Unfortunately, it doesn't seem to do anything.
Here is my code:
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
urls: [
{url:"http://test.dev/documentation/microservices/microservices.yaml",name:"All Microservices"},
{url:"http://test.dev/documentation/microservices/plans.yaml",name:"Plans"},
],
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = ui
}
I'd also like to set the primaryName to All Microservices.
Any ideas on where I'm going wrong?
The urls configuration option is supported in Swagger UI 3.0.18 and later.
You can use it instead of url like this:
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
urls: [
{url: "https://path/to/api1.yaml", name: "API One"},
{url: "https://path/to/api2.yaml", name: "API Two"},
],
"urls.primaryName": "API Two" // default document (if other than the first)
...
})
Result:
I'm trying to create SwaggerUIBundle where the urls will be of Azure Blob Storage container files.
For testing purpose I have hard coded the urls in here like this in my index.jsp file:
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
urls: [
{url: "https://backendsa.blob.core.windows.net/swagger-consolidation/*****", name: "SwaggerConsolidation"},
{url: "https://backendsa.blob.core.windows.net/swagger-consolidation/*****2", name: "SwaggerConsolidation2"},
],
dom_id: '#swagger-ui',
deepLinking: true,
spec: location.host,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region
These urls are pointing SAS urls for Azure Blob Storage files and are accessible while hitting in open network.
But while I deploy the code it gives below error :
Fetch error
NetworkError when attempting to fetch resource. https://backendsa.blob.core.windows.net/swagger-consolidation/*****
Fetch error
Possible cross-origin (CORS) issue? The URL origin (https://backendsa.blob.core.windows.net) does not match the page (https://router-sc.dev-wus.digitalservices.com). Check the server returns the correct 'Access-Control-Allow-*' headers.
Any insight over the issue would be helpful.
According to the error you provide, you need to configure CORS in Azure blob. Because the swaager UI application is a SPA application. when we call the rest api from a domain different from your website in the application, we will get CORS issue. Regarding how to configure it, please refer to the docuemnt.
For example
Allowed origins: *
Allowed verbs: DELETE,GET,HEAD,MERGE,POST,OPTIONS,PUT
Allowed headers: *
Exposed headers: *
Maximum age (seconds): 86400
In our swagger.json we are setting basePath to /api, however, when the application is deployed in docker container, the context path is not /api. This could be different thing and we don't know what it is so we can't hard code it.
I am trying to set requestInterceptor as per the following guide, in order to catch the request and modify the url path perhaps:
https://swagger.io/docs/swagger-tools/#customization-36
But it seems requestInterceptor is being ignored. Is this possible? If not, how can I set the correct path at runtime?
This is my code in index.html
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "../api-docs/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
requestInterceptor: function(request) {
window.alert(request);
},
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = ui
}
We are using Swagger 2.0
Upgrade to the latest version from here, or update your node package. I had the same problem because I downloaded the distribution before requestInterceptor support was added.
I am trying to consume Gateway OData Services in sapui5 app.
Metadata - /sap/opu/odata/SAP/ZUSER_MANAGE_SRV/$metadata as follows:
UserdataSet - /sap/opu/odata/SAP/ZUSER_MANAGE_SRV/UserdataSet as follows:
MY CODE
var oModel = new sap.ui.model.odata.ODataModel("http://Host:Port/sap/opu/odata/SAP/ZUSER_MANAGE_SRV", false,"USER","Password");
var app = new sap.m.App("myApp",{});
var oTable = new sap.m.Table("list1", {
growing: true,
growingThreshold: 200,
//mode: sap.m.ListMode.SingleSelect,
columns: [
new sap.m.Column({
header: new sap.m.Label({text: "ID"})
}),
new sap.m.Column({
header: new sap.m.Label({text: "First Name"})
}),
new sap.m.Column({
header: new sap.m.Label({text: "Last Name"})
})
],
items: {
path: "/UserdataSet",
template: new sap.m.ColumnListItem({
cells: [
new sap.m.Input({value: "{EUname}"}),
new sap.m.Input({value: "{EFirstname}"}),
new sap.m.Input({value: "{ELastname}"})
]
})
}
});
oTable.setModel(oModel);
var page1 = new sap.m.Page("page1",{
title: "App",
content: [oTable]
});
app.addPage(page1);
return app;
Getting error as - uncaught exception: [object Object].
Detailed Error:
Please help, whats wrong with my code?
Your OData service needs to be on the same server or needs to appear to be coming from the same server as your UI5 application. If it's not on the same server you should get Gateway to produce CORS headers.
Please find more info on CORS and how to get Gateway to produce these headers here: http://scn.sap.com/community/gateway/blog/2014/09/23/solve-cors-with-gateway-and-chrome
The Error is not very clear maybe chrome will show an more detailed error in this case.
If your application server and odata service are not from the same origin, the SOP (same origin policy) restricts this action.
Two pages have the same origin if the protocol, port and host are the same for both pages.
see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy for more details.
you can start chrome with --disable-web-security flag:
In CMD:
C:/<path to chrome app>/chrome.exe --disable-web-security
!!! ONLY FOR DEVELOPMENT REASONS !!!
I am very new to js and chrome extentions and am trying to make a chrome extension that gets the current tabs url and adds a '&flash=on' at the end. my code doesn't seem to want to work right
manifest.json
{
"name": "FlashOn Chrome",
"version": "0.1",
"description": "Changes default to flash player",
"permissions": [
"tabs"],
"content_scripts": [
{
"matches": ["http://www.stream.com/*"],
"js": ["script.js"]
}
]
}
script.js
function updateUrl(tab){
var currentURL = tab.url
var newurl = currentURL.replace(currentUrl + "&flash=on");
chrome.tabs.update(tab.id, {url: newurl});} chrome.browserAction.onClicked.addListener(function(tab) {updateUrl(tab);});
its for a streaming site that has html5 video and flash video but the flash is only accessible by adding the &flash=on to the end of the url
Not sure what you're trying to accomplish here: are you trying to change the location of the page, from the current URL to the URL with &flash=on` added on to it?
Also -- the script here seems to be incomplete: could you provide a complete script?
One obvious problem: you've got currentURL and currentUrl:
var newurl = currentURL.replace(currentUrl + "&flash=on");
Note that in a content script you can get and set the URL of the page with location.href.