Python3 web-server: Difference between localhost and 127.0.0.1? - python-3.x

I'm creating a local web-server in python for web-page testing purposes. While testing the web-page, I get two different results depending on whether I open localhost:8000/index.html or 127.0.0.1:8000/index.html in the web-browser (Chrome).
In the first case, it pulls an older version of the index.js file (from like days-ago old); but the 127.0.0.1 version pulls the correct file. So why would I be getting two different javascript files depending on the source when both are technically from the same directory? Where might I find the days-old file at?
I run the server from the html directory using the command:
python3 test_server.py
Index.html, Index.css, Index.js and test_server.py are the only files located in the directory...
Thanks,

So this is a caching issue. The Python webserver is not even requesting the new js file from a couple days ago was pulled on localhost Whereas the one on 127.0.0.1 was either expired or never pulled, so chrome pulled a new one.
To do a hard pull in chrome, right mouse click and then click on inspect. This opens the dev tools. Now right mouse click on the refresh page button and click on 'Hard Reload'. This will tell chrome to disregard any cached files and instead pull them from the server.
To avoid having to do this each time:
Click on the network tab in the devtools and make sure the box disable cache is checked.
However, be aware this will slow down load times on other sites, because no site will use caching with that box checked. So make sure you uncheck it when you are done doing dev work.

Related

Chrome Node DevTools Inspector stopped listing files

Title says it all. I haven't made any major code changes and the debugger is still connecting. However, it isn't listing any files:
Did something change in the Node dev tools to stop these files from showing up? This is all very mysterious and I've seen instances of other developers 'losing' their source folder listings when using --inspect with Chrome Node DevTools.
However, Cmd/Ctrl-P still lists the files and clicking on file names in the logs still takes me to the files (assuming I don't get some mysterious alternate empty version). Why can I no longer navigate my project's file system from Node Debugger on Chrome?
I have checked to make sure that the files are loaded (they are, as you can see, properly running and these particular microservices are responding as expected and pass tests). So I don't think it's an issue with my code.

How do I test file download using intern framework?

I have a requirement where I need to write functional test for download a file and testing its contents.
So i can say there are two parts.
1) Ensure clicking on a link downloads a file
2) Reading the file an checking its contents. Its a csv file, so I Can possibly do some manipulation with the content.
There are several issues with doing this. One is that if you're running a browser on a remote system, you'll need a way to get the file back to the system running Intern. The second issue is that you'll need to know where the downloaded file ended up when it was downloaded. A third issue is that some browsers (FF and IE) pop open OS-level dialogs that Selenium can't deal with.
The first question is: do you really need to download a file in the browser? It sounds like you may be testing a service rather than the browser, in which case you may be able to just download the file using Intern and inspect it there.
Assuming you do need to download a file via the browser, you should be able to configure a browser to not open a confirm dialog and to download the file to a known location, which at least handles 2 of the 3 issues mentioned above. Note that I haven't actually tested this.
In Firefox you can setup a test profile and use it when running tests. You'll likely need to configure the following properties:
browser.download.dir: 'path to download folder'
browser.download.folderList: 2
browser.helperApps.neverAsk.saveToDisk: 'text/csv'
browser.download.manager.showWhenStarting: false
For Chrome you'll pass options through the environment descriptor. The specific options should be:
'profile.default_content_settings.popups': 0
'download.default_directory': 'path to download folder'
Once you've setup the browser, your test code would need to click the link, then wait for some indeterminate amount of time (Selenium doesn't provide any sort of download progress data), then grab the file from the Intern test itself (using a network request or local file operation) to inspect it.

Local server not reflecting updated files

I'm fairly new at user local servers. I'm using the http-server which is a package from Node. I'm using it to host an HTML5 game using the Phaser library. I have image assets I'm using in the game, and I sometimes update these assets. When I do, the changes to the images aren't reflected in the game. I've tried restarting the server but that doesn't help. It usually takes some time for them to update, maybe about an hour. Any ideas what's going wrong?
The browser might be caching your code and/or assets.
In Chrome, with dev tools open (Right click -> Inspect element) you can right click on the refresh button and 'empty cache and hard reload'.
There's an option -c that refers to the cache time (max-age) in seconds [3600]
(e.g. -c10 for 10 seconds).
To disable caching, use http-server -c-1
You can see more information by enter http-server -h (for help)
You can disable cache in Chrome DevTools under "Network".
Whenever you reload a page while DevTools is open, it will clear the cache.
Alternatively, use the hard refresh keyboard shortcut (Mac):
CMD+shift+r
You can try to use live-server instead. It works for me.
npm install live-server -g
And you can start it simply by the command live-server.
Make sure your html file is in the correct location. A couple of times I've been editing my html and js files and then at some point I might cut and paste the files into a new folder. I'll change the reference to the new directory. But I forget that I need to reopen the html and js files from the new directory. Instead I keep editing them from the old directory and refreshing the browser wondering why nothing is changing. It's because the files I'm editing are the versions in the old directory. I need to close them and then open the files that are in the new directory.

Website loading deleted file

Working on this website I was going to add a simple .hide(); and onclick animate(); functions to a menu, but the menu div wasn't closed (stupid mistake). When I upload the file to the live website it hides everything in the website cause of the open div tag, obviously I fix it and also delete the jQuery function but when I upload the file to the FTP the website is still showing the old file for some reason.
More info: I already deleted the cache/cookies/history off this computer and reloaded the page and re uploaded the file. Also tried in 4 different computers with 3 different IPs I did a search of all the files and the code is not there anymore. Deleted the directory and it still shows up.
As i can suggest from your question, i can say its a stupid mistake. Happened to me a few times.
I would try the following:
Make a working folder of your "new" website - locally
Delete EVERY file and folder from your server (of course only your whole website)
Get sure that nothing is displayed when you open it at the browser, should be fail
Now load your local folder completely to the new, empty space at your FTP
Rather than re uploading the file. Delete it, visit it in your browser and verify you get a 404 and then upload it again.
I have had this problem before when re-uploading a file in some FTP clients.

Unable to upload files; file upload modal displays CP Home

I am tearing my hair out with a file weird file upload issue that I have never run into before. For some reason I’m unable to upload images via the file manager (both in the file manager itself and if I upload with a custom field using the “file” fieldtype). Strangely, if I add files directly to any of the file upload directories, and sync the files, everything works fine.
After selecting the file and hitting “upload file” (see 01_choose_file.jpg) the modal window displays the CP homepage in an iframe (see 02_upload_progress.jpg).
Has anyone else seen this? Does anyone know how I can start troubleshooting this?
Background Info:
I’m running EECMS v2.5.2 - Build Date: 20120606 in MAMP (only 2 out of 15 sites I have set up locally are not working)
I have tried uploading images/files using the latest versions of Chrome, Chrome Canary, Safari, and Firefox (OS X 10.7.5)
This issue is showing up on the two latest sites I’ve started dev’ing locally on, no other site (locally or otherwise)
Things I’ve done:
Checked Apache/PHP error logs; they don’t show anything
Confirmed file upload paths and file upload directory settings are correct – I can sync files that i manually move into the various file upload directories
Permissions are fine; image manipulations and thumbnail creation work fine if I manually add files to the upload directories
Tested various other 2.5.2 installs I dev on locally and they work fine (settings on these two new sites are identical to sites that work)
Only a handful of native add-ons are enabled
“Apply XSS Filtering to uploaded files?” setting Yes or No does not make a difference
Huge thanks for any help!
I can't post images so here are links to the images:
01_choose_file.jpg: http://expressionengine.com/?ACT=51&fid=105&aid=16264_Jiof3p0V1gfEEFrpC55G&board_id=5
02_upload_progress.jpg: http://expressionengine.com/?ACT=51&fid=105&aid=16265_mjGH02xK2fIFZJI6kruP&board_id=5
I have sorted this out. I went back through to make sure I disabled all third party add-ons and I had forgotten to uninstall the "Quickee" extension http://devot-ee.com/add-ons/quickee. For now that seems to be the culprit.
I've submitted the bug to Matt (the developer) and it should be patched up soon.
The ExpressionEngine filemanager sends out a AJAX POST request to the following URL:
http://YOUR_ADMIN_CP_URL?S=0&D=cp&C=content_files_modal&M=upload_file
Have you tried loading that URL yourself? You should get a page like this
But maybe EE is trying to POST to a different URL. You can find it by uploading a large file and while it's uploading using Firebug and in the Network tab at the bottom of the list you will find the URL EE is posting to

Resources