Basically, my thought process is as follows.
Client/browser requests html file login.html. This file contains a form with a username and password field. The submission button sends a POST request to the server with the given user and password field values. Simple, so far.
The server then checks a folder /users of JSON files of the naming convention username.json. For instance, if the client submits the username "John", it checks to see whether or not the file John.json exists. If it does, it compares the password value submitted in the POST request to that of the JSON file. If that matches, it returns the login-success html file, otherwise redirects back home.
That's where my problem lies. If it succeeds, I also wan't it to 'respond' with the JSON file matched to it, but the request seemingy only allows for the response to be one content-type, or to be read from a single file.
So, I'm just not sure how the client will know which JSON file to read based on the given response. I'm sure there's an easy solution and that I'm being an idiot, but any help would be appreciated.
Thanks in advance!
You can respond an HTML file and when document is load, respond the json file,
for example if you use jquery as your client side framework:
$(document).ready(function(){
$.get(URL_To_JsonFile,Params,function(data){
//do somthing with json file
})
})
In the end, I decided to use the Sockets.io module in order to pass the client my json data.
This enabled me to open up a TCP connection on the back of my HTTP server between the server and the client. When the password submitted matches the password in the json file, the server emits a "login-success" event to that client and with that event passes the json file used in the server. The client side script accepts that response and parses that data for use. Here's a sample:
server.js - Server side script
if (password == json.password) {
io.on("connection", function(socket){
socket.emit("login-success", json);
}
}
app.js - Client side script
var socket = io("http://localhost:8888");
var username;
socket.on("login-success", function(json){
username = JSON.parse(json).username;
}
This also means the data only has to be read in once, the object it's assigned to is just passed to the client via the TCP stream established between it and the server. Hoorah!
Thanks very much for the responses everyone.