Running PHP frontend site with node.js page connecting both together - javascript

I have created a php site, doing the basic stuff reading from a sqlite database, logging in etc. This is currently running on xampp on port 80 and all is fine.
I have created another page which is ran on node.js it uses socket.io and express.io.
Currently running on port 8080.
I want to click on a link on the php site that directs me to the node.js page which are both on different ports.
I hope this is understandable, I have done alot of searching on the matter and cannot find a viable solution.

Maybe
Link
If i am wrong please specify your Problem

Change the link to include the port of the node server, like so:
Node Page
If you want to go back from Node to PHP:
PHP Page

Related

How to establish a SSH MySQL database connection for a Electron App?

I'm making a app with the Electron Framework, within this the user needs to register an account to be able to use this app.
This worked great when making this for my localhost database, but creating connection with the MySQL server that is running on a dedicated server seems not working for me, and also insecure since people can unpack the .asar file and see the database credentials..
So, I've heard about 'SSH Connection' but can't figure out how to set this up, and get this up and running for my Electron app.
I am using XAMPP to create a MySQL/Apache server and I use HeidiSQL to enter the MySQL server.
For your info, I've never used Electron before and this is my first time using it. I've also never used a SSH connection before (at least, not that I'm aware of.) so a guide for newbies would be nice.

Node.js / Express - how to think about client-side database work? (e.g. can't use require())

I've been through a number of Node.js, Express, and other tutorials/posts, and I'm struggling with how to think about connecting to a database on various pages throughout a webapp.
I would like to run a Node.js app (with a server.js file that connects to a database) and then query that database as needed on every page throughout the app.
So if I have an inventory.html page I should be able to have javascript that queries the inventory table and displays various inventory items throughout that html page.
Problem #1. I can't find a way to use mysql on any client-side pages, since javascript can't use node's require() function client-side. As detailed in this StackOverflow post ("require is not defined").
Problem #2. I can't figure out an elegant way to pass a database connection to other pages in my app. A page can send a POST request back to the server.js file, but this really isn't as flexible as I want.
I'm really looking for the modern, preferred way to do a bunch of PHP scripting in my Node app. Can anyone guide me to the right way to do this? Thank you!
You just can't directly call mysql from the client. Even if it worked imagine that anybody could modify the SQL queries and access all your data.
The only way how to do it is this:
js client app ------> js server app -------> mysql
You just must have 2 apps: one running in the user's browser sending requests to the server and the other running on the server answering the requests.

Angularjs: Node server that supports html5mode?

I'm locally developing an Angularjs app. I'm using the same node web server as in the Angularjs tutorial. The link to the code for the web-server on Github.
The problem is that I can't seem to get html5mode to work on the node server. What I understand so far is that i have to add a base href to my app and rewrite the server code. I tried rewriting the node web server code, but I failed and it didn't work. Could someone please help me in what i should exactly change? Or does someone maybe already has a version of the server rewritten?
The link to my app looks like this: http://localhost:8000/app/index.html
Also refreshing the page on a html5 link doesn't work. Like this: http://localhost:8000/schedule.
Thanks
You have to rewrite incoming requests that aren't to your REST endpoints respond with the same response as the request to /app/index.html.

Is it possible to run a Node script from a web page?

I'am searching for days now but could not get an answer.
I would like to do the following:
User connects to editor.html (Apache2 with basic http auth)
User want to open a file (lets say /home/user1/myfile.txt) on the server with his user/pass (same as in passwd)
Node.js Script gets startet with user rights from above and user can edit file
The Node Script will handle the connection via websockets and read/writes files.
I think the biggest problem is that its not possible to run a node script on the server from a web page... and I donĀ“t want to involve any php/cgi scripts... only Apache and Node.js / JS.
Please also comment or answer if you know that it is really not possible...
Thanks!
Kodak
Edit: The workflow should be the following:
User access webpage -> enters his credential (same as in passwd) -> node.js script gets started with the user rights of the logged in user -> files getting read or written with user rights
Biggest Problem: who starts the Node.js script? Apache? How?
I hate to be this person, but...
That is not the way node is designed, it is designed to use the event loop, I would recommend having node serve the static files, maybe using apache as a proxy, then when someone requests a certain page, doing what ever needs to be done, if you really must spawn a child process, use child_process.spawn, as for the rights of the user, I recommend just passing in a code, like 1=admin, 2=user, 3=guest, and the child process can do what is needs.
Use Socket.io - Official Socket.IO Website
You can also use Express with socket IO to create a separate app server. - Express JS Website
You may want to consider security implications of allowing a user to connect directly using their server side account. There are also many applications available that already do this that you might consider implementing instead of writing your own, with all the properly embedded security that will be required.
Let your users GET static auth.html page (via apache) without any authentication.
Let form submit action is some auth.js (Node.js script). This auth.js check if user's authentication is success. If so it starts node.js server, setups socket.io on it and redirects user to some editor.html.
In this case as you can notice that there is an authentication based on node.js scripting. If you want basic apache2 one I can recommend you the next scenario:
There is auth.html and editor.html pages on the server. Last one placed in /private folder and direct access to this folder is denied by .htaccess. So when the user pass apache2 authentication in auth.html he GET this auth.html which is empty document with onload event handler that send AJAX to auth.js (Node.js script). Node.js get private/editor.html and send it to user like /editor.html.
In this case user never has an access to editor without passing authentication. And after authentication node.js server is started and socket.io is setup and everything fine.
I found a solution:
It is possible to write a custom authentication program for apache with mod-auth-external:
https://code.google.com/p/mod-auth-external/
With basic authentication enabled the webserver would pass the credentials to a script/program and this can then run the node app.

Sending commands via Telnet/TCP to web page (Node.js)

I'm new to node.js
To illustrate my question, I'll use an example:
Client sends a command via telnet/tcp to socket server (ie 'telnet 192.168.0.10 8888' then 'showDiv1')
Command is forwarded from server to a Web page
depending on command, different are displayed on the web page
There are plenty of examples on the node.js website, but it seems difficult to combine the sample scripts to produce the desired functionality above. Any ideas?

Categories