Does NodeJS's https module follow redirects? - javascript

I'm using the NodeJS https module to fetch pages and process them during testing. I can't find any mention of following redirects either there or in the http module documentation.
From experience I would assume that an https.request does not automatically follow redirects (through response.headers.Location), but I'd like to be sure.

Nodejs doesn't follow redirects by default.
The following article explains this http://syskall.com/how-to-follow-http-redirects-in-node-dot-js/

Related

URLs don't work within production - return 404

This issue seems to be well documented but all solutions people suggest on posts don't work for me :/
I managed to fix urls giving 404 on my localhost by applying
--history-api-fallback
to the "scripts" package.json
however when I move the production over to my apache2 setup, any url I manually type or refresh returns 404, on site navigation works fine.
for example, http://www.craftmc.net/ works but http://www.craftmc.net/login returns 404, despite that url working if i navigate to it on site.
I saw a post saying use this .htaccess,
https://hastebin.com/alifavacil.apache
Sadly it didn't work. :/
navigation in question - https://hastebin.com/xevecefoda.xml
You need to configure Apache to serve your app on all URLs that it's supposed to handle.
By default, Apache will only serve your app when the user requests the specific path where the app is located, say for example www.example.com
If you now try to visit www.example.com/user/123, Apache will try to find a file named "123.html" inside the "user" folder. You have to tell Apache that what it should do is reply with your app even if the path requested by the browser doesn't actually point to your app within the filesystem on the server.
You can do this in several ways, but a common one is to use mod_rewrite. For example, you might try something along these lines:
DocumentRoot "/var/www/example.com"
AliasMatch "^/myapp" "/opt/myapp-1.2.3"
<Directory "/opt/myapp-1.2.3">
RewriteEngine On
RewriteBase "/myapp/"
RewriteRule "^index\.html$" "welcome.html"
</Directory>
For more information about mod_rewrite and the various directives it uses, refer to the documentation, and/or google.

Firebase can't authenticate after building electron app

I have a problem with Firebase, React and Electron. When I use my app in dev, I use the localhost to load with react-scripts start , so it's loading in http://localhost:3000. I use this url to load my app with Electron.
BUT when I am trying to go in production, I use the electron-builder. I build my app with react-script build, it's create the build folder, and for the electron app, I change the loading url for file://${path.join(__dirname, "../build/index.html" I use build -c.extraMetadata.main=build/electron.js. It's now loading perfectly. BUT When I try to authenticate nothing happen and in the console, it says :
code : auth/operation-is-not-supported-in-this-environnement
message : This operation is not supported in the environnement this is running on. "location.protocol" must be http, https or chrome extension and web storage must be enable
How I can resolve this ?
My hypothesis it's because I don't write the url of my app in Authorized domains in Firebase Sign in method, but there is no url for my app, it's local. Does I need to load a server to employ Firebase ?
I see a similar post but without answer
I think it's because the SDK thinks it's running from a Node.js server environment. Currently, OAuth sign in with popup or redirect is not supported in Electronjs. You would need to get an OAuth credential from an electron compatible library and use the signInWithCredential API.
Firebase is looking into supporting signInWithPopup/Redirect in this environment.

Azure Applications Insights node js module not working - Fetch API cannot load error

I am trying to integrate npm's application insights module (https://www.npmjs.com/package/applicationinsights) into my React js application.
My source for doing this is:
import appInsights from 'applicationinsights';
appInsights.setup(applicationInsightsKey).start();
The problem I got is that in my Chrome Developer tools I can see a preflight request made to https://dc.services.visualstudio.com/v2/track.
But in the console I can see the following error:
"Fetch API cannot load https://dc.services.visualstudio.com/v2/track.
Request header field content-encoding is not allowed by
Access-Control-Allow-Headers in preflight response."
Do you have an idea how can I fix this issue?
The node.js module you are using is the AI SDK for Node.js server. And As the React js applications are client applications in javascript, technically they are different.
Please try to use ApplicationInsights-JS.
Additionally, you can refer to https://azure.microsoft.com/en-us/documentation/articles/app-insights-web-track-usage/ for more info.

Dillinger stuck at "prepping all the things" when running locally

Update: I have checked the console for error, it catches
Uncaught ReferenceError: require is not defined
According to some online posts, it is probably due to the use of require on the browser side. require is meant to be a syntax for Node, which is used on the server side. But the use of [Browserify][browserify.org/] made this possible.
Im not sure how this works but hope someone may give me some advice.
I was trying to run Dillinger on my own Macbook Pro (13-inch)
I followed the instructions on the README.md but when running locally it shows this.
PS. As suggested by post here, I modified the package.json that the dependency installation can proceed.
Dropbox config not found at /Users/[name]/dev/dillinger/plugins/dropbox/dropbox-config.json. Plugin disabled.
Github config not found at /Users/[name]/dev/dillinger/plugins/github/github-config.json. Plugin disabled.
Google Drive config not found at /Users/[name]/dev/dillinger/plugins/googledrive/googledrive-config.json. Plugin disabled.
OneDrive config not found at /Users/[name]/dev/dillinger/plugins/onedrive/onedrive-config.json. Plugin disabled.
express deprecated app.configure: Check app.get('env') in an if
statement app.js:19:5
connect deprecated multipart: use parser (multiparty, busboy,
formidable) npm module instead
node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:56:20
connect deprecated limit: Restrict request size at location of read
node_modules/express/node_modules/connect/lib/middleware/multipart.js:86:15
connect deprecated methodOverride: use method-override npm module
instead app.js:27:19
express deprecated app.configure: Check app.get('env') in an if
statement app.js:56:5
Express server listening on port 8080
http://localhost:8080
When I send a request, it shows this :
Evernote not implemented yet.
GET / 200 34.139 ms - -
GET /css/app.css 304 4.351 ms - -
Then when I tried to open Dillinger at localhost, it is stuck at "Prepping all the things..."
Anyone has any idea why this is so? I am new to Javascript and Node.JS so forgive me if the question looks dumb.
Many thanks in advance!

socket.io.js not loading

I know there are a bunch of questions on this already, but none have answered it for me, and plus mine is slightly different.
I'm starting the socket.io server in node using this:
var io = require('socket.io').listen(8000);
My terminal says everything is ok:
info - socket.io started
Now I am trying to load the .js file in my clientside browser using this url:
http://<hostname>:8000/socket.io/socket.io.js
I dont get a 404, it just hangs forever. I've also used a network utility to ping port 8000, and it seems to be open fine.
I installed node and socket.io just yesterday, so they should be the latest versions. Can anyone shed any light on this? Thanks!
Turns out the reason I could never request the .js file was because my company network blocks all ports except the usual ones (80, 21, etc), so `I would never be able to communicate with port 8000.
Use express.js. Place the socket.io file in public/javascripts folder and add this line to your html
<script src="/javascripts/socket.io.js"></script>
I think this is the best way. When you're writing http://<hostname>:8000/socket.io/socket.io.js
node tries to find a folder named socket.io in your project's public folder. And the file socket.io.js in it.
If you don't want to use express.js you should catch the request and try to load a file if no routes were found for your request (what actually express does) because node doesn't know what to do for requests which don't match any routes in your server.
And I recommend to use the socket.io.min.js file (it's smaller and it's in folder node_modules\socket.io\node_modules\socket.io-client\dist)
You have to start an http/https server to access it via http/https. Simply starting an socket.io server won't do. Do the following:
var http = require('http');
var app = http.createServer(),
io = require('socket.io').listen(app);
app.listen(7000, "0.0.0.0");
Then I can access the file http://localhost:7000/socket.io/socket.io.js
sockets.io uses websocket protocol (ws://). See the wikipedia page.
You need to get at least 3 pieces working together.
Serve some HTML (/index.html will do just fine) so there's a web page. This file should contain the socket.io client <script> tag. For this you need the http server portion of the starter examples. You are missing this and that's why browsing to your server just hangs.
Serve the socket.io client. Socket.io will do this for you automatically when you pass in your http server function to it. You don't need full express as this can be done with just node's http module as per the first example on the socket.io docs.
Some javascript to actually do something with the socket. This can be the content of a <script> tag in index.html or a separate file. If it's a separate file, you need to set up your http server to actually serve it.

Categories