Send redis message with html/javascript - javascript

I'm trying to find a way to send a redis message to a specific channel from a website. I think this might work, but I don't know how to use it and there is very little explanation.

Redis is supposed to only connect with a server, not directly with a client such as a browser (it's actually impossible to directly connect to redis from a browser).
You can achieve that running webdis on the server with redis and connecting to it from the browser, resulting in an infrastructure similar to this:
Client Server
----------------------
|
|
Browser ---> webdis
| |
| |
| v
| redis
Note that it would not be secure, because the client on the browser could do whatever he wants with your redis database.
Usually, a custom server program is implemented that forward your commands to the redis server in a controlled way:
Client Server
----------------------
|
|
Browser ---> custom server
| |
| |
| v
| redis

Related

Set base path for all the images in by react app

I am basically building a MERNy app and I want to fetch images saved on my back-end server and show it on the front-end.
My question is, how can I set the base path of my server for all the images that I fetch on my website like I can set Axios baseUrl. Because right now I add this to my src tag: http://localhost:5000/images/myImage.jpeg. How can I make it so that I add only /images/myImage.jpg and let it fetch from the server? Because whenever I deploy my back-end server I will have to change all the occurrences of localhost with my domain.
You can use a Reverse Proxy to abstract the image path. This way you can have three servers running behind a single domain.
Express - is the API server for all your Ajax request. When a request is sent into MyDomain.com/api it will be redirected internally to API_SERVER_INTERNAL_HOST:3000/
Web Server (Images) - it another Web Server that serves static files but its files will be the images the user uploaded. When a request is sent into MyDomain.com/images it will be redirected internally to API_SERVER_INTERNAL_HOST:3001/
Web Server (React) - is a Web Server that serves static files (HTML, CSS, js, fonts, images, etc..) that build your app.
/api :3000 +---------------------+
+---------------->+ Express |
| +---------------------+
|
MyDomain.com +---------------+ | / :8080 +---------------------+
+-----------------+ Proxy (Nginx) +------------------->+ Web Server (React) |
+---------------+ | +---------------------+
|
| /images :3001 +---------------------+
+---------------->+ Web Server (Images)|
+---------------------+
This setup is varied flexible and if in the future you will like to use 3rd party Web Server for hosting images you can just change the proxy config.
See the following for getting started with Nginx reverse proxy setup: https://www.nginx.com/blog/deploying-nginx-plus-as-an-api-gateway-part-1/
In addition:
you can use MinIO as the Images Web Server. MinIO uses the same interface as S3 and is really nice if you need to manage a Static files Web Server (the express app will use the MiniIO API to upload the user image to the Web Server)

Can Dymo JavaScript API connect to Dymo web service which is hosted on a different machine on the same network?

I have a task to build an application online which would allow printing labels through Dymo LabelWriter 450 Turbo printer. The goal of this application is - company employees submit data to that needs to be on stickers via website and when they click 'print', all the labels are printed by one of the office machines.
After launching Dymo web service on the mentioned machines, I am able to print labels if I click print while I am in those machines through JavaScript API that Dymo provides, however if I try accessing the script that I wrote from other computers on a network, printing does not work. This is due to the fact that JavaScript API points to 'localhost'.
I downloaded JavaScript API locally and replaced 'localhost' in it with the IP addresses of machines on a network, but now, API when trying to access web service times out. Is there any way of solving this?
Here is visualization of how everything works:
-------------------------------------------------
| Local machine, 198.168.0.1 |
| |
| Dymo webservice runs here. |
| |
| If JavaScript API is run, it communicates |
| with webservice without any problems, |
| printing works. API points to 'localhost' |
| |
-------------------------------------------------
Here is visualization of what I want to do, but what doesn't work because API times out when trying to communicate to web service:
-------------------------------------------------
| Local machine, 198.168.0.1 |
| |
| Dymo webservice runs here. |
| |
-------------------------------------------------
|
| LAN
|
-------------------------------------------------
| Local machine, 198.168.0.2 |
| |
| Javascript API is downloaded here and |
| 'localhost' is replaced to 198.168.0.1 |
| |
| After user accesses a webpage and clicks print,|
| API tries to contact web service, but times out|
| |
-------------------------------------------------
Thank you in advance!
Dymo binds on the loopback adapter, so you can only connect with 127.0.0.1 or localhost. In your case, I would advise to share the printer on the network just like any other printer and install the Dymo Label software on each workstation while installing the Dymo as a network printer.

Web browser that only runs JavaScript, to use as a development sandbox

I'm looking for a JavaScript read-evaluate-print loop for development prototyping.
For now, I am using the Firebug Console, the Firefox Developer Tools Web Console, repl.it, jsFiddle, plunker, or one of the other online tools.
The problem is that a Firefox console is linked to the tab/window on which I opened it. The web based ones have restrictions too; for instance, jsFiddle.net doesn't show console output and repl.it does not let me use Fiddler to watch an XMLHttpRequest.
What I would like is a Windows desktop application that is very similar to the PowerShell ISE but that runs JavaScript instead.
+-------------------------------+----------------------------------+
| | |
| JavaScript to Run | Console Output |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+-------------------------------+----------------------------------+
It still needs to have the same functionality as the Firebug Console or Firefox Web Console. I.e. it needs to evaluate JavaScript, output console messages, and send HTTP requests via XMLHttpRequest. Does this exist? Where can I get it?
I ended up using PhantomJS, Notepad, and the Windows Command Line. First, install PhantomJS. Then...
Edit
Open Notepad.
Create a JavaScript file.
Type console.log('foo');
Save.
Run
Open the Command Line.
Run phantomjs myfiddle.js.
Press Ctrl + C to exit phantom.
Repeat
Switch to Notepad. Edit. Save.
Switch to Command Line. Run.
Here is a screen shot of a streamlined process running on my machine.
It works with XMLHttpRequests, I can inspect the request with Fiddler, and the nice-to-have is that we can adapt it for use with Vim to create an integrated scripting environment.
As a professional developer, I have to point out this makes absolutely no sense. The code you write is not going to be understandable or meaningful in terms of "console output", unless you write toy code, or what you want is actually a live-reloading server environment, where you write html+js, and you want the browser to autoreload when you save updated files. In which case live-server may already be all you need.
If, on the other hand, what you need is a REPL like python or the like, then just Node.js is literally what you want. But then that doesn't make the most sense because why on earth would you edit your source code in a REPL instead of using a code editor...?

Nodejs getting all needed scripts and stylesheets route from a page request(without browsers)

I'm wondering if it is possible for me to get all the scripts and stylesheets routes I need from a html file.(not using browsers at all.)
for example:
I run index.html, and the website need ./style.css and also need ./script.js and lot of images.
How could I know what index.html need the routes of style.css and script.js and images.
another question: Does the browser works like rendering HTML file while it need some files, the browser request to server and wait for response? So is there a way I could use nodejs to analog the action and not using browsers?
You have to specify the location of your static content in your app.js file from where server will serve the files to browser when index.html will render.
for example if i have following directory structure
ROOT
|
---public
| |
| ----css
| | |
| | ----style.css
| | |
| |
| ----js
| | |
| | ----script.js
| | |
| |
| ----images
| |
|
|
---app.js
|
---index.html
|
Browser requested urls format are
css - > <link href="/css/style.css" rel="stylesheet" type="text/css" />
js - > <script type="text/javascript" src="/js/script.js"></script>
after that you have to add following code in your app.js file;
app.use(express.static(__dirname + '/public'));
if express is not installed in your system install it form cmd using command
npm install express
add following line of code in app.js
var express = require('express')
, app = express();
Find out a good way to solve the problem is using phantomjs(http://phantomjs.org/), network-monitoring is probably something I'm looking for.

Heroku Foreman Exits on Express.js bodyParser() call

When running foreman start, I see the following message
> foreman start
20:38:55 web.1 | started with pid 3896
20:38:55 web.1 | Development
20:38:56 web.1 | connect.multipart() will be removed in connect 3.0
20:38:56 web.1 | exited with code 1
20:38:56 system | sending SIGKILL to all processes
I was wondering why this was the case, since running node server.js does not appear to terminate the server.
Here is the segment of code that appears to cause the app to terminate with exit code 1:
var app = express();
app.configure(function()
{
// More config things above
app.use(express.bodyParser()); // This line is causing the issue
// More config things below
}
The above is code using the Express.js framework. Removing the above call to express.bodyParser() allows the server to run (via foreman). The problem is, I'll need the body parser module in order to parse my incoming get/posts requests.
Any help on this issue would be much appreciated.
I have no idea why foreman exits when deprecation warning is reported in express, but you can eliminate this behavior replacing app.use(express.bodyParser()); with
app.use(express.json());
app.use(express.urlencoded());
connect.multipart() will be removed from bodyParserin next version of Connect and this is probably the issue. You can find more info in Connect documenattion and/or in this StackOverflow Q&A.

Categories