JS - Intercept all incoming XML and Websocket request client-side - javascript

I am working on a web proxy right now and it works, but I need some Javascript that could see all incoming XML, Fetch, and websocket request and rewrite them. Only problem is that I don't know how to. I really need this in pure javascript. I apologize if I can't show any code here.

if you want to read the content of the requests, you need to set up a web server.
you can use http and websocket module to set up a simple server,
but I recommend using a backend framework, such as express.

Related

How to make server-side API requests?

I'm working in javascript(React) to create a web app that makes use of multiple APIs(Spotify, Twitch, Youtube) and so far I have been using Axios to make
the REST calls successfully. But now I have begun running into Cross-Origin Resource Sharing (CORS) errors and I have been told
that I need to make calls to external APIs from a server instead of from my client. I've never made API calls from a server and
have some questions:
Everything I am doing is currently running locally using Node and I dont have a "server" unless that's what Node counts as. Do I need to get a "server"?
Should I be creating my own API and hosting it on some server so that I can call that API from my javascript code?
How do I create my own API if that's what I should be doing?
Is there a different language I will need to use to make server-side api calls?
Everything I am doing is currently running locally using Node and I dont have a "server" unless that's what Node counts as. Do I need to get a "server"?
React comes with a bunch of development tools that use Node, including a development server. It isn't designed for production use though, so you shouldn't use it for that.
Should I be creating my own API and hosting it on some server so that I can call that API from my javascript code?
Yes.
How do I create my own API if that's what I should be doing?
Write some code which accepts an HTTP request, gets the data you want to respond to it with, and makes an HTTP response.
Express.js is a popular way to do this in Node. You can combine it with Next.js to apply server-side rendering for your React app (resulting in better performance, accessibility, reliability, and SEO).
Is there a different language I will need to use to make server-side api calls?
You can write your server-side code in any language you like.
I assume you are hosting your application on a development nodeJS server, therefor you
will need an extra server.
Yes. Create an API and call it from your frontend.
Create a server which takes http requests and does your stuff according to the route
chosen.There are many examples on how to do this with for example nodeJS+Express on the
internet.
The Language you use for the server side is your choice.

AngularJS Server Backend Handle Incoming HTTP Requests

I just started learning AngularJS for my website development, and its perfect for what I need. However, I'm very new to web programming and I've been looking for the answer to my question for a while now, and I couldn't get a clear response. I'm wondering how I can handle incoming HTTP Requests in my AngularJS application.
For example, I'm going to have a computer running a program that is going to be constantly sending HTTP Post requests with data to the web server running my Angular app. I want to be able to parse the information in the app, and display the data using Angular's data binding. But, I can't figure out how in Angular you can listen for incoming HTTP requests, parse the data, and send back a response.
AngularJS is designed for front-end web apps. You use to make an HTTP request from the users web browser to a webserver listening for such calls. But angular itself can't listen for them.
If you want to be able to listen for a HTTP request you will want to try either apache/php or nodejs/express. nodejs will probably work best for you because you can program in javascript.

AJAX Fetch Cross-Domain HTML

I fear I may be trying to do something that certain security policies are specifically designed to forbid.
So there's a certain site with a certain AJAX-based chat application. It periodically polls the server and receives HTML fragments in return. I am looking to write an alternate mobile frontend that directly queries the existing backend using JS (i.e. does not use my server as a reflector).
Two main issues here that make this different from most such questions:
The server owner wouldn't mind me doing this but he's not going to go out of his way to help me, and so the format for talking with the server is not something I can change. That is, the server doesn't talk JSON let alone JSONP. It's HTML fragments but for my purposes that's essentially text.
I need to have the return value available to parse manually. It should not be automatically parsed/inserted/what-have-you through inclusion in the DOM or some other such mechanism.
If anyone has some advice on this matter, I would really appreciate it.
You could use a server side script to proxy it through your server.
You could use YQL as the middle man and use JSONP or CORS.
Tell the person on the other server to set up CORS for your server (tell them to add a header for each request, e.g. Access-Control-Allow-Origin: example.com).
could you create a php proxy,
ajax send url to fetch to local php(or other serverside script)
php uses curl to fetch that page and returns result.

Implementing a very small HTTP server in c/c++ and want to use AJAX

I want to have a dynamic webpage that automaticly updates some information, this information should be received from my c/c++ application using HTTP. I have set up a socket and can send HTML and Javascript files to the browser.
I don't know how to move on. How to encapsulate my data into XMLHttpRequest objects? Or maybe this isn't the way to go? The problem is that my c/c++ application will be run on an embedded system that can't really support php or something like that.
I can't really understand how XMLHttpRequest works, I only find a lot of client examples on the web and not much about how a server should handle it.
A server should handle it as any other request. From the servers point of view, it's a normal HTTP request. Return the data that the client asks for! This is usually a HTML fragment, some XML or some JSON.
Ajax just send normal HTTP GET POST ... request, you should make sure your response header is correct, such as Content-Type.
How do you send information to the browser? The browser is client-side. To get information, you must either query the server (which you say is written in C++). If you want your client to receive request, you should probably emulate a server-like behavior using NodeJS.

Javascript remote events?

Is it possible to have a web service notify web clients when something occurs via HTTP request/response? Right now my client has to poll the server using HTTP Requests at an interval to check for updates, but it would be far more convenient if I could register a javascript function to the server from my client and have it be simply called when server state changes.
Note that the web service is written in Python and utilizes HTTP APIs (I think it uses cherrypy, if that's relevant).
If this is possible could someone point me to some tutorial that explains how to do this or give me a basic understanding of how this can be accomplished?
Look into Comet
You can't start a request from the server to the client. You can only poll the server (which you did), use a hidden iframe, use a plugin, or use the new HTML5 WebSockets which allows the server to send a message to the client.
If you are into Node.JS, look into socket.io and hook.io
https://github.com/hookio
https://socket.io

Categories

Resources