Things I want to do
This code uses JavaScript to check whether the program is running on a server or locally.
(This is used when running test code locally and production code on the server.)
Protocol-based verification
You can check this in the protocol part of the URL.
When running locally, the URL protocol is ‘file:’, and when running on a server, it is ‘http:’ or ‘https:’.
Therefore, you can check it with the following code.
if (location.protocol == "file:") {
/////local
} else {
//////server
}Result
I was able to check whether the program was running on the server or locally using JavaScript and then process it differently.


コメント