Admin on rest HMR example - admin-on-rest

Does anybody have an good example with HMR (hot module replacement) working with admin-on-rest?
Currently I got errors
Warning: You cannot change <Router history>

Related

Laravel 9 (Vite) shared on local network on https

I am building a web app that uses (mobile devices's) camera, but this is working only on https and localhost.
The web app is served locally using WAMP 3.2.9.
I've managed to use the secure protocol (https) within my wamp configuration, but I'm having problems when I want to share my app to my local network so I can view the app on my phone and test the camera functionality.
In the older versions of Laravel (which used webpack) this was very easy using browsersync, but now, using Vite I don't know exactly how to do this.
My local domain is myapp.test and can be accessed using both http and https.
I tried to use npm run vite --host, which shows the local and network address as well (ex. 192.168..), but when I visit that address on my phone, I can see only the Vite default page This is the Vite development server that provides Hot Module Replacement for your Laravel application., but not the app itself.
In my vite.config.js file I added that ip from vite network:
server: {
https: true,
host: '192.168._._'
},
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: [
...refreshPaths,
'app/Http/Livewire/**',
],
}),
mkcert()
],
Note that I also used the mkcert vite plugin to allow me to use https.
Now I'm confused about the vite service that runs on port 5173 by default and the app that should run on port 443 to be on https.
I've also tried using `php artisan serve --host 192.168.. which works on my local network, but it doesn't work with https, so I had to focus on WAMP only.
So how can I have my app shared among my local network with https?
I'll explain about how Vite works compared to Webpack to hopefully help you understand a little better.
Both Webpack and Vite create a bundle of files when using the build commands to compile for production. Using the dev command, that it seems like you're using, they work a little differently. While Webpack watches for file changes to recompile the bundle and BrowserSync then reloads your assets for you, Vite starts a local server to serve the compiled files. This means that you don't proxy your original domain like with BrowserSync. Vite also creates a file in your public folder called "hot", which tells Laravel which url it should use when using the #vite() directive or the Vite::asset() method. Because of that you can use your original domain myapp.test even for the hot reloading of the dev command. I don't think Laravel actually supports --host and if it doesn't I haven't been able to find it or figure it out.
I did find https://github.com/Applelo/vite-plugin-browser-sync to hopefully solve your testing on other devices but I couldn't get it to work with https, otherwise I'm afraid you might have to look into something like ngrok and use the npm run build command instead of dev until better support is built into Laravel.
Update:
To configure the BrowserSync plugin you have to manually configure the proxy:
VitePluginBrowserSync({
bs: {
proxy: 'http://myapp.test/' // The usual access URL
}
})
Since it doesn't seem like Laravel supports --host I have been able to find a workaround: because Laravel reads the asset host URL from the hot file in the public directory, you can replace the contents with the external Vite URL like http://192.168.1.37:5174 after running npm run dev --host. This will make Laravel use that URL when referencing any assets.

How to properly connect Nuxt.js with a laravel backend?

I am starting a new project, Nuxt.js for the frontend and Laravel for the backend.
How can I connect the two?
I have installed a new Nuxt project using create-nuxt-app, and a new laravel project.
As far as I have searched, I figured I need some kind of environment variables.
In my nuxt project, I have added the dotenv package and placed a new .env file in the root of the nuxt project.
And added CORS to my laravel project, as I have been getting an error.
The variables inside are indeed accessible from the project, and im using them
like this:
APP_NAME=TestProjectName
API_URL=http://127.0.0.1:8000
And accessing it like this:
process.env.APP_NAME etc'
To make HTTP calls, I am using the official Axios module of nuxt.js, and to test it i used it in one of the components that came by default.
The backend:
Route::get('/', function () {
return "Hello from Laravel API";
});
and from inside the component:
console.log(process.env.API_URL)//Gives 127.0.0.1:8000
//But this gives undefined
this.$axios.$get(process.env.API_URL).then((response) => {
console.log(response);
});
}
What am I doing wrong here?
I have tried to describe my setup and problem as best as I can. If I overlooked something, please tell me and I will update my question. Thanks.
Taking for granted that visiting https://127.0.0.1:8000/ in your browser you get the expected response, lets see what might be wrong in the front end:
First you should make sure that axios module is initialized correctly. Your nuxt.config.js file should include the following
//inclusion of module
modules: [
'#nuxtjs/axios',
<other modules>,
],
//configuration of module
axios: {
baseURL: process.env.API_URL,
},
Keep in mind that depending on the component's lifecycle, your axios request may be occurring in the client side (after server side rendering), where the address 127.0.0.1 might be invalid. I would suggest that you avoid using 127.0.0.1 or localhost when defining api_uris, and prefer using your local network ip for local testing.
After configuring the axios module as above, you can make requests in your components using just relative api uris:
this.$axios.$get('/').then(response => {
console.log(response)
}).catch(err => {
console.error(err)
})
While testing if this works it is very helpful to open your browser's dev tools > network tab and check the state of the request. If you still don't get the response, the odds are that you'll have more info either from the catch section, or the request status from the dev tools.
Keep us updated!
Nuxt has a routing file stucture to make it easy to set up server side rendering but also to help with maintainability too. This can cause Laravel and Nuxt to fight over the routing, you will need to configure this to get it working correctly.
I'd suggest you use Laravel-Nuxt as a lot of these small problems are solved for you.
https://github.com/cretueusebiu/laravel-nuxt

Cross Site Access Not Allowed (using Django 2.1.5)

I am working on an app using Django 2.1.5 with DRF 3.9.1 and on firefox browser console, I am getting this error:
downloadable font: download failed (font-family: "FontAwesome" style:normal weight:400 stretch:100 src index:2): bad URI or cross-site access not allowed source: http://softpro-admin-templates.websitedesignmarketingagency.com/assets/vendor_components/font-awesome/fonts/fontawesome-webfont.woff?v=4.7.0
After some googling, I came across this link https://github.com/ottoyiu/django-cors-headers/
As mentioned in the document I have installed the package and made the following modifications in the settings file:
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', #added at the top
-----
]
INSTALLED_APPS = [
'corsheaders',
]
But still, I am getting the same error. Can someone help me with this issue?
I'm assuming you're not the owner of softpro-admin-templates.websitedesignmarketingagency.com
Somewhere on your site, you're using fontawesome version 4.7.0 (A common icon font) but providing the above host as the source for this font. Due to CORS policies in most browsers, the host has to specifically allow this if the site the request originates from (yours) was fetched from a different domain (origin).
As the maintainer(s) of softpro-admin-templates.websitedesignmarketingagency.com likely don't know anything about your site, this hasn't been done. Change the src of fontawesome to your own server or the CDN suggested by fontawesome to solve this.

React-apollo + material-ui: server side rendering not work with express

I have a big problem to make a boilerplate for a complete react application using graphql (react-apollo) and material-ui.
I trying a lot of shit, but i always as the same problem:
Warning: Prop "className" did not match. Server: "MuiSvgIcon-root-60 MuiListItemIcon-root-127" Client: "MuiSvgIcon-root-60 MuiListItemIcon-root-123"
if i'm logged (problem is come from the Drawer component visibly), and:
Warning: Did not expect server HTML to contain a <h1> in <div>.
if i'm logout (the Drawer is not showing).
You can found the complete example here: https://github.com/CocoJr/docker-sf4-elasticsearch-graphql-react-express/tree/master/volumes/node
This is my server.js file: https://github.com/CocoJr/docker-sf4-elasticsearch-graphql-react-express/blob/master/volumes/node/src/server.js
Thx a lot man.
I solved my bug:
https://github.com/mui-org/material-ui/issues/10649#issuecomment-408624288
Just using this in your bash works fine: sed -i 's/material-ui\/core\/SvgIcon/material-ui\/core\/es\/SvgIcon/' 'node_modules/#material-ui/icons/es/utils/createSvgIcon.js'
And be sure to ALWAYS use /es versions of material-ui, particulary for the SvgIcon coming with #material-ui/icons/... => #material-ui/icons/es/...

trying to rebuild a Reddit Rails App from two years ago (User Agent & BootStrap)

Two years I used the Reddit API to pull stories into a Rails app I built. I wanted to come back to it to refresh myself on RoR. It seems like I got all of the updates working and can sometimes run it, but here are my issues:
1) Reddit now requires Oauth2 for API requests. I'm using the Redd gem and am able to get authenticated, but I get the 429 error (too many requests) error.
I copied from the Redd instructions the following into my model (substituting my info from my registered Reddit app page):
# Authorization (Web)
w = Redd.it(:web, "_myClientId_", "_My_Secret", "_myRedirectURI", user_agent: 'ruby:edswartz.com.myredditapp:v1.0 (by /u/edswartz')
url = w.auth_url("random_state", ["identity", "read"], :permanent)
puts "Please go to #{url} and enter the code below:"
code = gets.chomp
w.authorize!(code)
# Authorization
re = Redd.it(:script, "_my_Client_ID_", "_my_secret_", "_my_user_name_", "_my_password_", user_agent: 'ruby:edswartz.com.myredditapp:v1.0 (by /u/edswartz')
re.authorize!
edAgent = 'User-Agent: ruby:com.edswartz.trueQuotes:v1.0 (by /u/edswartz)'
response = JSON.load(RestClient.get('http://reddit.com/.json'),{'User-Agent'=> edAgent})
After successfully authenticating (copying and pasting the code into the console) I usually get a 429 error. What am I doing wrong? I'm not trying to spoof the user agent, but have put it in manually. I just don't know how else to do it.
The times that I do get in and see the site appear it is obvious that Bootstrap has not loaded. In looking at the Rails-Bootstrap documentation I see where the Gem name has changed and the application css. My /app/assets/stylesheets/application css looks like this:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
#import "bootstrap";
*/
Again, not sure this is right either but have tried to comply with the read me from https://github.com/twbs/bootstrap-rubygem
Any help anyone can provide on either of these issues would be much appreciated.
I resolved the Bootstrap question. I was using Bootstrap 4. When I went back to Bootstrap 3, and moved the #import directives in the SASS file out of the comments section AND changed the "span4" class to "col-md-4" everything worked.
The user agent seems to be working more often so it might have been a caching issue?
In any event, onward.

Resources