Double base path when using push with basename - react-router

I've come across an issue which I've been trying to figure whether I'm just doing something wrong or whether it's an actual bug. After a lot of searching, I still can't figure out if I'm doing something wrong or if I've found an actual problem.
Part of the reason as to why I'm so confused is also because I found the intersection between react-router and history a bit confusing. It took me a while to figure out exactly how to use history's enhancer functions with react-router and I still think the issue might lay there.
I have a test case here:
https://github.com/trodrigues/react-router-basename-test
http://trodrigues.github.io/react-router-basename-test/
And the problem is:
Clicking the button issues a this.context.router.push call to navigate to /content/path
I'd expect it to navigate to http://trodrigues.github.io/react-router-basename-test/content/path
Instead it navigates to http://trodrigues.github.io/react-router-basename-test/react-router-basename-test/content/path
Some additional detail:
If I use the <base> tag instead of the useBasename enhancer this works fine. However, given that I have a slightly different setup for dev and production, using an environment variable to define the basepath would be more helpful, rather than manipulating the <base> tag at build time.
The sample app I uploaded is a minimal subset of the app I'm working on. I removed everything else that didn't matter.
The issue does not occur when running this locally with a basepath set to an empty string.

After some further investigation I figured out react-router already uses the useBasename enhancer when using useRouterHistory, which is the cause of the problem as the enhancer gets executed twice.

Related

Missing Schema for WordPress theme.json

According to the docs, one can simple add
$schema": "https://schemas.wp.org/trunk/theme.json",
to the beginning of the JSON file to load the schema
VS code gives me the error that it's missing:
And sure enough, going to https://schemas.wp.org/trunk/theme.json it doesn't exist:
I've seen posts such as this one about missing schema which says to go to https://schemas.wp.org/wp/5.9/theme.json but same result. Searching around it seems like their security certificate expired at some point, but surely they resolved that many months ago.
I'd like to resolve this to get the benefits of schema (autocomplete / intellisense) in the file, especially since the file is getting larger and this is a large project with multiple people working on it.
Help appreciated.
It seems like https://schemas.wp.org/trunk/theme.json is not reachable for you even though it is online (I can reach the URL). The url forwards to ttps://raw.githubusercontent.com/WordPress/gutenberg/trunk/schemas/json/theme.json which might be accessible for you. If yes, you can add this direct url as the value for $schema.

Open index.html but it turns out undefined

I am a beginner of JS, I usually use live server in VS code to see if my code works properly. A weird thing happens to a project, when I run the live server, the path becomes undefined, then the website crashed. I tried to open the file from the file manager, the same situation.
My original filename: file:///D:/Desktop/trashcar/index.html
When it opens on the browser: file:///D:/Desktop/trashcar/undefined
I am not sure if I accidentally change the settings, and the unexpected thing is only in this project. I've tried to search possible cases, but it seems I am the first case. I will be thankful if someone can give me a hint on this.
Just set the pathname in your browser to file:///D:/Desktop/trashcar/index.html
You don't need a server to view static HTML.
I tried to create a new file and past the original code line by line and it fix now. I still wonder why this happens only to that file.

New MySQL query on each page refresh

I'm trying to to guarantee that fresh JSON is sent to my page every time a user clicks refresh. Currently, if the JSON is updated the webpage will not reflect the change until Apache is restarted.
I have tried the following approaches -
Create a nocache function and call the decorator in the page function
I have tried putting headers in my HTML
Using Command + Shift + R in Chrome for MacOS for a "hard" refresh
No good... I'm beginning to think I'm misunderstanding something. Can someone point out the error of my ways? I copy and pasted the code presented in those links. The first link even speaks about JSON specifically. I can show my exact code being used if desired, but like I said; copy and paste.
Maybe its not even a caching issue, I'm not sure, but I'm open to any ideas!
EDIT:
I know now that my no-cache headers ARE being passed to the HTML. The issue lies somewhere in that the Flask isn't asking MySQL for updated data every time the page is loaded, only when Apache is restarted. So even if fresh data is in MySQL DB it will not be displayed for the user unless Apache gets restarted.
I finally found another post on Stack Overflow regarding my question.
Turns out I need to make my DB connection and form the JSON in the same function. Before I was calling the data from the DB in a separate function and then referencing it to create JSON and pass it to the HTML in a different one. Now everything is inline see HERE.

eureka.dashboard.path doesn't seem to have any effect

This could be a problem with static resource loading, but when using a custom path for the eureka dashboard, all I get is a blank page. No error, nothing in the log, just blank. Removing the custom path makes the dashboard available on "/". Here is the project to reproduce the problem:
https://github.com/knetikmedia/cluster-manager-test
Thanks
eureka.dashboard.path takes effect, but /eureka path is a default prefix used for instance for the purpose of locating static resources. Try using some different value, like /dashboard - it worked for me.

How to configure Netbeans code entry point when you use mod-rewriting

I am developing a website in PHP and I am using mod-rewrite rules. I want to use the Netbeans Run Configuration (under project properties) to set code entry points that looks like http://project/news or http://project/user/12
It seems Netbeans have a problem with this and needs an entry point to a physical file like http://project/user.php?id=12
Has anyone found a good way to work around this?
I see your question is a bit old, but since it has no answer, I will give you one.
What I did to solve the problem, was to give netbeans what it wants in terms of a valid physical file, but provide my controller (index.php in this case) with the 'data' to act correctly. I pass this data using a query parameter. Using your example of project being the web site domain and user/12 as the URL, use the following in the NetBeans Run Configuration and arguments boxes. netbeans does not need the ? as it inserts that automatically, see the complete url below the input boxes
Project URL: http://project
Index File: index.php *(put your controller name here)*
Arguments: url=user/12
http://project/index.php?url=user/12
Then in your controller (index.php in this example), test for the url query param and if it exists parse it instead of the actual Server Request, as you would do normally.
I also do not want the above URL to be publically accessible. So, by using an IS_DEVELOPER define, which is true only for configured developer IP addresses, I can control who has access that special url.
If you are trying to debug specific pages, alternatively, you can set the NetBeans run configuration to:
http://project/
and debug your project, but you must run through your home page once and since the debugger is now active, just navigate to http://project/user/12 in your browser and NetBeans will debug at that entry point. I found passing through my home page every time a pain, so I use the technique above.
Hopefully that provides enough insight to work with your project. It has worked good for me and if you need more detail, just ask.
EDIT: Also, one can make the Run Configuration Project URL the complete url http://project/user/12 and leave the Index File and Arguments blank and that works too without any special code in controller. (tested in NetBeans 7.1). I think I will start using this method.