Issues regarding reloading a react-based webpage - node.js

I'm a student working on a project to benefit other students, and I am currently facing a problem with reloading with any other url than the main path.
The webpage is written from scratch (more or less) in React with no backend, but I still hoped that it would work. I am using react-router to change sub-directories.
I have understood that there is a difference between server- and client-url's, and that this issue most likely is related to that. In the app's main directory "webpage.com" everything works fine untill the page is refreshed. If a sub-directory such as "webpage.com/link" is "called" directly, I recieve an error. You can go and try for yourself btw.
Does anyone know of a nice way to fix this? Do I need to implement something like Node.js to fix this? If so, how? I would prefer not to use a hot-fix such as redirecting all sub-directory calls (such as "/link" (an actual page) or "/kejrngo" (jibberish) ) to "/".

I've cloned your project locally and it seems you have a problem with the server. As you said yourself it seems that only open url for your page is http://ifistudenter.no where at the beginning all application is rendered. After you try to refresh the page you are looking for a path that isn't available on the server and that is the reason you get 404.
What seems to be a problem is React Router itself with Apache server:
Please look at this: https://www.malikbrowne.com/blog/using-react-router-with-apache hope it helps

Related

Socket.io.js can't be found (404)

I've developed a small chat application with Socket.io and Express, currently deployed on my droplet at digital ocean. You can see it live at https://keleheart.com/chatapp. It currently doesn't work because the server is giving back a 404 for the chatapp/socket.io/socket.io.js script I have at the bottom of my html file, should be able to see that when you visit the site and hit f12
I've been through a few fixes already that were popular on here such as This one and this one and I've even tried changing the script from local to a CDN as depicted here , and the CDN seems to work better,(still gives the 404 but it then no longer says io isn't defined??) but it still doesn't produce the output I need.
You are able to review my repo on my Github Page for this as well, there's just the index.html file for the client and then the chatApp.js for the server. The error is coming from my html file but all the fixes have told me to manipulate my package.json, server variables, and nothing has worked so far. My server still cannot find chatapp/socket.io/socket.io.js
Have you tried creating the /socket.io folder next to index.html, and putting a copy of socket.io.js inside of that? That has always worked for me, but you might have to hunt through the node_modules folder to get the file. This always fixed it for me.
And of course, be sure to actually serve the file using express's static method.
Your browser is giving you the correct error message. Since /socket.io/socket.io.js does not exist on the server, the browser displays the server's 404 message.

My website is defaced — how do I fix it?

My website is defaced and every time I load it, there appears a page with some message in some Turkish language and the title of page is 'hacked by 58'.
I tried searching this web page in my public_html directory but couldn't find this html in any directory. Yet still it loads when we visit the website.
Any help?
nginx or apache? locate the configure file,inside the file there is a line kind of 'root',that's path of your index folder,enter that folder fix index.html.
Btw,if your server is hacked,it's highly possible running dangerous programs ,you'd better reinstall your sys,and try not to be hacked,such as use ssh-key login method.

Magento 1.9.3 index.php redirect loop

I am working on an E-Commerce website project which I created in localhost. It worked fine, until I moved it online.
Since I moved it online, I've had issues accessing the admin page and the index.php. I've managed to make the admin page work and can now access the backoffice without any issues, but my index.php still shows me an "error: too many redirects1" page.
What's happening?
Main page of my website is stuck in a redirecting loop (chrome error message : this url tried to redirect you too many times)
Everytime I reload the main page, the url switches between www.mydomain.com and mydomain.com (might be an htaccess issue?)
What I've done to try and solve the problem:
I have checked everything in core_config_data table to make sure
the right urls are written in web/secure/base_url and
web/unsecure/base_url. They are.
I have manually cleared the var/cache and var/session from my
FTP.
I have cleared all cookies / cache from Chrome / Firefox
I have reuploaded the files and database multiple times, thinking it might be due to a corrupted file from the upload.
I have tried to edit the htaccess, but it didn't change anything.
What should I do now ?
I feel like I've tried everything.
As it's my first time with magento, I'm sure it's some dumb thing I might not know about, but I've read nearly every single post about this kind of issues on this website and haven't found anything to resolve it.
So I'm asking you. I'm willing to try every single idea you throw at me, as I've been stuck on this issue for a while now ^^
Thanks for reading :)
Weird, It seems that You make everything right. Try to find and update all url settings in core_config_data: select * from core_config_data where path like '%url%'.
You can try update web/url/redirect_to_base config to 0 (if you have 1).
Remember to clear cache.

Changing localhost server files are served from using Node (Webstorm /maybe IntelliJ)

I'm not sure what I'm missing here, so hopefully someone can help me out. I'm working on a project where we're using Node and in the Run/Edit configurations I've down the following:
Node interpreter: This is the path to the node.exe file
which I checked out from Subversion
Working directory: this is where the "app.js" file is, this is the
path that from the command line you type node app.js and it starts the server
JavaScript file: app.js This is the name of the file that actually creates the server
Now from the main nav bar when I do Run / Run my server the box at the bottom pops up and tells me that Express server is listening on port 3000. Cool.
I can navigate to localhost:3000/myPage.html and I can get to the page just fine.
I added as JSON file to the same directory on my hard drive that myPage.html is in, and I can navigate to that as well by localhost:3000/largeTestData.json.
So the server is up and running and serving file as it should. My problem is that in my Webstorm project, I want to make an AJAX request to that largeTestData file. I do so using jQuery like:
var data = $.get('localhost:3000/largeTestData.json');
data.done(function(data){
console.log('here is your data');
cnosole.log(data);
})
When I do that I get the error (in Chrome)
XMLHttpRequest cannot load localhost:3000/largeTestData.json. Cross origin requests are only supported for HTTP.
and so I look at the URL and I'm seeing:
http://localhost:63342/
Obviously Webstorm has started the server correctly, but when I view an HTML file, it's not using that server (which, of course is why I'm getting the CORS error.
There's some fundamental stuff here which I'm obviously not getting. I need my IDE to deploy to the Web server that it started up, but it's not doing that. Please, someone give me a once over on all the technologies that I'm missing out on here.
WebStrom didn't start your node.js server, but serves static pages by its own internal HTTP server which doesn't know anything about node.js and Express.
The main problem:
When you start your node.js server, it's serving JSON files on port 3000. If you open an HTML-page with the little menu in WebStorm (where you can choose the browser), WebStorm opens the browser with an URL pointing to its own internal webserver running on a different port (e.g. 63342). JavaScript security prohibits loading data from a different host/port Same-origin policy.
It's not WebStorm's fault and you need a solution for this problem in production or you can't go live.
General Solution:
Either you have to ensure that HTML pages and JSON data come from the same host+port, or you can circumnavigate with (a) setting server-side headers ('Access-Control-Allow-Origin: *') as #lena suggested, or (b) using JSONP. Below you find some thoughts using nginx as a reverse proxy so from browser's point of view all requests go to the same host+proxy. It's a very common solution, but as mentioned above, there are other options.
Primitive solution:
Don't use WebStorm to open your browser. Load the page from http://localhost:3000/ and change the URL of the REST resource to $.get('/largeTestData.json'). You'll miss some comfort from your IDE, but you can immediately see that your program is working.
Comfortable solution:
As #lena suggested, there is a way to configure your Express/node.js as a server known to WebStorm. I haven't tried it, but I suppose you can then just press the Run-button and maybe the node.js plugin in WebStorm is as intelligent to know the static-maps in Express and know how to map an HTML-file to a web application URL and open the page in the browser with the URL served by your node.js application. (I'd be surprised once again if this really works magically, but maybe you can configure a mapping from files to URLs manually, I don't know.)
Dirty solution
With some options you can disable security checks, at least in Google Chrome. Then it's possible to load JSON data from a different port than your HTML page. I wouldn't recommend using these options (just my opinion).
Additional Hints
If you do more than just playing around with node.js and some UI fun and you have to serve your application "production-ready", then have a look at nginx to serve your static files and reverse proxy node.js requests from there. I'm using this setup even for development and it works like a charm.
Of course node.js / Express is able to serve static files as well, but IMO placing something like nginx in front of node.js (clustered) bring a bunch of advantages for production sites, e.g. load-balancing, ssl-offloading, avoid JSONP, in many cases performance, easier deployment updates, availability.
To get your code working, just change the URL in $.get() to full URL (including protocol):
var data = $.get('http://localhost:3000/phones.json');
In Webstorm 2016.3 (and probably earlier) there is now another option. Under the Configuration Settings for NodeJS runs, one can manually set the page and port to be loaded via Webstorm's "Browser/Live Edit" settings.
See the screenshot below for settings one can change.

CouchApp paths are wrong after import

I'm using CouchApp to push an existing html&javascript application. The application uses jquery and twitter bootstrap and it works perfectly fine from a regular web server / when opened locally.
(The application is basically a ready made app I bought and which I wish to redesign)
After I push the application (which is structured in many folders) I can't open it from couchdb since all the paths are "wrong".
My HTML files are under Page/PageType/Pagename.html so every css for example is accessed via ../../stylesheet/style.css but the URL can't be accessed when calling couchdb.
For example I have this page:
http://127.0.0.1:5984/coreadmin/_design/coreadmin/pages%2fother%2fsign_up.html
Which is displayed in the browser but without style/js/images because the path is:
http://127.0.0.1:5984/coreadmin/stylesheets/application.css (So _design/coreadmin is missing)
Is it possible to upload the project as is and make it work or do I have to go over all the files and fix the paths? (which means it will not work on any other web server...)
Thanks!
The problem was with the URL - by replacing the %2f to / everything everything is now working just fine.

Resources