React app not rendering on another pc from internet - javascript

What's up friends?
I am programming an app using React. The page loads me perfectly from my pc and on my phone using a local ip, if I connect to my public IP from another computer the page goes blank, and apparently it stays in a loop of loading files 0.chunk. js or something similar and never renders the page.
I already configured HOST and IP in the .env file but I still have the same problem.
UPDATE
I dont know why, but deleted and reconfigure .env file and it works

Related

os.platform() Not Working Correctly In Website

I'm using the built-in 'os.platform()' function in Node.js to get the home directory of a user when they sign in to a website so they can import files. In order to specify which path to look for those files in, I need to know the OS of the user's PC. When I run the code in my local server, it runs fine, returning "win32". However, when I deploy the website, it always reads "linux", which I can only assume is the operating system of the server. How can I make sure that "os.platform()" returns the client's OS and nothing else?
I should also mention that I am running this code with a console.log(os.platform()) in getInitialProps(). I've tried using navigator, window, and process.env.HOME but none of those have worked for me, as they always return undefined inside of getInitialProps().

Can CHMOD Changes affect data from loading to a page?

I have a linux website where data loaded to the page correctly all the way up until I started screwing around with chmod permission changes. I was making changes, because a js script I am using wasn't working for uploading and cropping an image, and I thought maybe it was a permissions thing in the image folders.
Anyway...
After I made changes to the permissions, rows of data no longer appear, however, I do know that a connection to the database works, because there is some data that is the username appearing in another section of the page.
I changed everything back to 755 for folders and 644 for files and the data rows just do not appear anymore.
Here's the kicker, the exact same files work fine on a localhost server I'm running on a Windows 10 PC. Same exact database too.
Does anyone have any idea what I did wrong? I have confirmed that the files on my localhost server match exactly the files on the website, and the connection for both servers is going to the same MySQL db.
I am truly stumped on this one.
Thanks
This is a Linux/Apache/Nginx issue, rather than the tagged Javascript/PHP/MySQL.
Both Apache2 and Nginx run as a specific user. The current Apache2 default user is www-data, which is a member of the www-data group. If permissions are changed to disallow this user access to files, they will not be able to be served by Apache.
You should make sure all assets are readable by the user your webserver is using (or one of its groups).
It's also worth noting that permissions on MySQL databases are different to Apache2/Nginx filesystem permissions. Being able to access database data doesn't mean your server's filesystem permissions are correct.
I'd also suggest you use Chrome's inspector to check whether your assets are loading; and check your webserver logs to see what errors are popping up.

png files failing to load when opening html file directly, but they load when opening from webstorm

I've been working on a game in javascript for my CS course. When I open the document by hitting run in Webstorm, it loads the game correctly, however when I just try opening the html file from Finder, the webpage opens but none of the png files I'm using for the sprites load. I opened Inspect Element in google chrome, and the javascript files loaded correctly but all the png files listed as canceled. This doesnt happen when the game is run from webstorm (when I run it from webstorm, all image files load properly).
When the game is opened directly from an html file (that's when I have the problem), chrome lists the path of the html document as the webaddress, although when opened from webstorm, it lists http://localhost:63342/CS%20Week%2010/CS105_Jessica.Davis_DogGame.html?_ijt=tmrr2fndgac82h07hlvt101gi4
How can I get around this issue so that when opening the html file from Finder it loads everything correctly? All image files are in the same directory as the html file.
Because of browsers security, loading files like this might not work from a url starting with file://
What webstorm is probably is making a local web server so that instead of saying file:// you could say http://. if any website was able to load images from file:// then any webpage you visit would have been able to search for any file on your computer and send it over the internet without your consent so browser often have these settings on. So you'd need a server. If you are working on your computer, you could make a local server just like webstorm and host your own files there. or host it on another service like github pages or codepen.
Now since all images are in the same directory, make sure that every time you call loadImage you use the images name and extension instead of saying /User/user/whatever_other_directory_you_have_it_under/image.png.
Once you did that you can make a local web server for the project. To make a local server, open Terminal (an application under utilities, you could spotlight search for it as well) and type cd, drag your project folder and drop it over terminal, and hit enter. Then type python -m SimpleHTTPServer and wait till it says something like Serving HTTP on 0.0.0.0 port 8000 .... Then taking the 0.0.0.0 and the 8000 you see in the example (yours may or may not be the same) go to your browser and type http://0.0.0.0:8000 (replacing the digits with whatever you got, not this link doesn't work until you do that)
Images should load alright. If you need to stop the server you can go back to terminal and hit control+C.
Note that when presenting your p5 sketch, no one else would be able to see the website on their computers if you make your local server. The local server is secluded to the device that is running it (although if their making their own local server and have your project files it should work just fine).
If you want the website hosted so that you could share a link with anybody in the world you could use codepen or github pages. If you go to codepen.io it should be self-explanatory although you'd have to upload your images to some image hosting site like tumblr or something and add the URL source of those images to codepen or you could put everything into github for even better results!
To use github pages you'd need to make a github account (preferably with your username being whatever you want your page to be named). Make a repository named insert_username_here.github.io. add your files to the repository (make sure to try to keep all sub directories and folder exactly as they are from your project folder). After a minute or two go to http://insert_username_here.github.io to admire your brand new hosted webpage!

Node webkit loading page by window.location.href and require is not a function

I have application writen in node webkit.
I have three pages: login screen login.html , dashboard.html and
page that is downloaded from server, unpacked from zip and fired by window.location.href from local directory.
This is the main functionality of application, give user ability to login to repository of applications and get the latest code of "game".
In login.html and dashboard.html node js is working properly. Login app uses window.location.href to load dashboard after sucesful login. The problem is that another page, loaded from local directory has problems with "require". Does someone knows why in first pages require is function, and in another is not.
There is node-remote package, but this page is not loaded from remote server. This page is loaded from local storage.
Am i misiing some behavior of nodejs. Is NodeJS code and all pages compiled on application start? or they are added to object of nodejs.
The answer is pretty simple. NodeWebkit uses folder where are stored and executed my html files as root folder. I moved html to app root, changed src of app.js and everything works great. From that place node-modules are visible for application.
Its funny that someone like me, without knowledge of basics in node, can make advanced desktop app, remote server for it ...

Chrome App - Dynamic Javascript

I have a Chrome App that displays slideshow/dashboard on the screen. Right now all of the website files (html and .js) are stored in the app. So when the application starts, it can be used completely offline because all of the files it needs are stored internally.
I'm looking for a way to host the dashboard's files (.js files) on a web server, that the app will query, pull down, and cache fresh copies of at startup. This will make it easier to update the dashboard but still allow it to be (mostly) offline.
I have been able to have the app query the server successfully and pull down the Javascript files as strings. Normally, I would just inject the JavaScript into the page but that's not allowed with Chrome Apps. My question is, how can I take the JavaScript (pulled down from the server) and load it in the page?

Categories

Resources