How to properly enable restful-keystone endpoint for model - keystonejs

Assuming I have a model named "Project", the documentation for restful-keystone suggests it should be as easy as the following to enable an API endpoint for it.
exports = module.exports = function(app) {
app.get('/', routes.views.index);
app.get('/gallery', routes.views.gallery);
restful.expose({
Project: true
}).start();
};
However, when I start keystone I get the following:
Rest is not enabled for galleries
Rest is not enabled for projects
Rest is not enabled for users
Can anybody explain to me what is going on and how to get this to work?

Found the solution after some research:
https://github.com/d-pac/restful-keystone/pull/5
This problem only occurs on windows, as the urls use path.join().
Use this https://github.com/d-pac/restful-keystone/pull/5/commits/0d8cf0c1514bad810fbc2345114d913cfb1e921a patch to temporarily fix your problem.
Unfortunately the maintainer has not merged the pull request yet.

Related

Setting up a devserver.proxy in Vue3 with Axios requests

Im currently looking into setting up a proxy within my application for working within Sharepoint to update the cookies manually for local testing. have been using this https://medium.com/#joy.blanks/frontend-frameworks-inside-microsoft-sharepoint-e7694aa43c5d for reference and trying to convert the informaiton into a Vue3 project.
At present im struggling to get any conversation made and not entirely sure where it is falling over, i have tried to enable the debug settings to see if that reveals anything, but not getting any logs out in browser or console
I have the following added to my module.exports (have emited some data):
devServer: {
proxy: {
'https://<sharepoint_target>/_api': {
target: target,
logLevel: 'debug', // this what you want
changeOrigin: true,
}
}
}
and the Azios request is:
await axios.get(`${config.cmsEndPoint}/_api/lists/getbytitle('${list}')/items`,{ params});
but not able to even see if the proxy is kicking in as from the console give me any updated information around if the proxy server is working. Im not sure if its because im using a full url or if this would make a difference. The <sharepoint_)target> and the cms endpoing are the same string
From here i can then look at add a new header into the request as part of the proxy bypass section for the authication when testing locally.

How to load JSON in Vue CLI without CORS error

I have a Vue.js project wrapped in an Electron app. From one of my components (src/components/MoviesTable.vue), I'm making an axios call to a local JSON file (public/data/multimedia.json), like this:
axios.get('./data/multimedia.json').then(res => {
this.movies = res.data.movies;
})
When I run npm run serve to serve the Vue app, I experience no issues. However, when I build the Electron app, I receive the error:
Access to XMLHttpRequest at '.../multimedia-index-app/dist/data/multimedia.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
I've tried using proxies to no avail. I know that similar questions about CORS have been asked on SO, which offer different solutions, but I'm a noob, and I need clearer instructions than the ones that I've come across.
Please let me know if you require more information. Any help in resolving this problem would be greatly appreciated.
Thanks in advance.
If the JSON file should be bundled with the app, you don't need Axios, you can have Webpack load it:
import movies from './data/multimedia.json';
And use it in the component:
export default {
data() {
return {
movies
}
}
}

How does vue PWA use the precache? I still get "Page does not work offline"

I have a vue application that I updated to have PWA capability. It uses the firebase messaging service that has overridden the service worker with its own firebase-messaging-sw.js file.
The service worker is registered, active and working, I have added the pwa in the vue.config.js file so that it generates the manifest.json. When you build the production version of the app the following code gets added to the top of the service worker.
importScripts("precache-manifest.7b51ac9589a6dc8041a85d8f1792defa.js", "https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
From what I see the percache works fine.
Should this be enough to get the site to work in offline mode?
Do I need to add some cache management myself?
What am I missing because I still get the "Page does not work offline" error message in Chrome's dev tools under the App manifest tab.
Looks like Google also picked up on the quick hack and the warning has returned.
So since of Chrome93 (AUG-2021) the quick hack, will not work anymore :
self.addEventListener('fetch', function(event) {})
Solution working "for now" (since we never know what requirements Google will add later on)
I've found a nice article which provides with a few solutions, the first one the author provides is Network-Falling-Back-To-Cache strategy:
your service worker will first try to retrieve the resource from your server. Then when it can’t do that — because for example, you’re offline — retrieve it from the cache (if it exists there).
self.addEventListener('fetch', function(event) {
event.respondWith(async function() {
try{
var res = await fetch(event.request);
var cache = await caches.open('cache');
cache.put(event.request.url, res.clone());
return res;
}
catch(error){
return caches.match(event.request);
}
}());
});
You can find all the information and alternative solutions in the article:
https://javascript.plainenglish.io/your-pwa-is-going-to-break-in-august-2021-34982f329f40
I hope this will help futur visitors.
Additional side note:
using the above code you might encounter the following error:
service-worker.js:40 Uncaught (in promise) TypeError: Failed to execute 'put' on 'Cache': Request scheme 'chrome-extension' is unsupported
This error is caused by chrome extentions like Augury or Vue dev-tools. Switching both off will cause the error to disappear.
You need to add this line in the serviceworker. It fools the browser into thinking that the page will work offline:
self.addEventListener('fetch', function(event) {}) // add this to fool it into thinking its offline ready

Grails using Google authentication with the Spring Security plugin

Has anybody managed to successfully combine Google authentication with Burt Beckwith's awesome Grails-based Spring Security plugin recently? I wanted to go down that path with Grails 2.4.3, and after some fooling around (and recompiling the donbeave version of the plugin at https://github.com/donbeave/grails-spring-security-oauth-google) I was able to find a combination of references that would compile and run together. I ended up adding the following lines to my BuildConfig.groovy:
compile ':spring-security-core:2.0-RC4'
compile ":spring-security-oauth:2.1.0-RC4"
compile ':spring-security-oauth-google:0.3.1'
I found, however, that the changes created by the initialization command “grails s2-init-oauth” don’t give me all the modifications that I need in order to move forward. I ended up adding a block to my config.groovy that looked like this:
oauth {
providers {
google {
api = org.grails.plugin.springsecurity.oauth.GoogleApi20
key = 'MY KEY'
secret = 'MY SECRET'
successUri = '/oauth/google/success'
failureUri = '/oauth/google/error'
callback = "${baseURL}/oauth/google/callback"
scope = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
}
}
}
These config definitions specify a callback in my code (referred to above as ./oauth/google/callback) which didn’t exist. After I brought in a controller from the recommended example (https://github.com/bagage/grails-google-authentification-example), substituted "/springSecurityOAuth/onSuccess" for "/oauth/google/callback", (and registered by redirect URL through the Google Developers Console) I found that my onSuccess method was indeed being called, but the data structures referenced in the controller were wrong, and it seemed as if I would need to largely rewrite the controller logic in order to get everything working. I have to assume that other people want to accomplish Google-based authentication in the same way that I do. Is there an complete operational example somewhere? Or can someone tell me where I’ve gone wrong in my attempt to utilize the standard plug-ins? Thanks for any assistance.
You need to use spring security oauth plugin also. Please refer here https://github.com/cazacugmihai/grails-spring-security-oauth,
When you click on button, it hits the authenticate action inside Oauth controller which gets
authentication()
url of the google. After successful authentication, it hits callback() action Of Oauth controller which then redirects to onSuccess() action of SpringSecurityOauthController which then saves the info to OAuthId domain and finally redirects to the successUri given in config.

Can no longer access the list of API descriptors after installing Glimpse

We would like to use Glimpse in our ASP.net MVC project but are running into a problem when accessing the list of Web API descriptors.
We have installed Glimpse.Mvc4 1.2.2 using the Nuget Package Manager.
The following snippet gets all API descriptors and it works fine before we install Glimpse. After installing we do only get an empty list.
IEnumerable<ApiDescription> apiDescriptors = System.Web.Http.GlobalConfiguration
.Configuration
.Services
.GetApiExplorer()
.ApiDescriptions
Does anyone know why this call does not work when Glimpse is installed?
The problem is that the Glimpse ASP.NET module wraps all routes in its own objects. So API Explorer ignores them (thinks that they are not Web API routes).
To work around this issue, you must initialize a fresh copy of System.Web.Http.HttpConfiguration instead of using GlobalConfiguration.Configuration.
// need to create a custom configuration instance because the default one can be
// processed by Glimpse and be thus full of wrapped routesthat the ApiExplorer
// does not recognize.
var config = new System.Web.Http.HttpConfiguration();
WebApiConfig.Register(config);
// these line is useful if you use WebAPI Help page package
HelpPageConfig.Register(config);
Controllers.HelpController.Configuration = config;
// otherwise just get the `IApiExplorer` interface from the fresh configuration:
var apis = config.Services.GetApiExplorer().ApiDescriptions;