I have a node.js server that serves index.html with text-based password entry. After checking the server password, you must start the download for the client. The client should not see the location path where the file is on the server.
here is my server.js:
var http = require('http'), qs = require('querystring'), fs = require('fs') ; console.log('server started'); var host = process.env.VCAP_APP_HOST || "127.0.0.1"; var port = process.env.VCAP_APP_PORT || 1337; http.createServer(function (req, res) { if(req.method=='GET') { console.log ( ' login request from ' + req.connection.remoteAddress ); fs.readFile(__dirname +'/index.html', function(error, content) { if (error) { res.writeHead(500); res.end(); } else { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(content, 'utf-8'); } }); } // method GET end else{ // method POST start console.log('POST request from ' + req.connection.remoteAddress); var body = ''; req.on('data', function (data) { body += data; if (body.length > 500) { // FLOOD ATTACK OR FAULTY CLIENT, NUKE REQUEST req.connection.destroy(); console.log('too much data')} }); req.on('end', function () { var postdata = qs.parse(body); var password = postdata.passwordpost ; if (password == '7777777') { console.log('the password is right, download starting'); // ??????????????????????????????????? here I need help from stackoverflow } else{ console.log ('password wrong'); fs.readFile(__dirname +'/wrongpassword.html', function(error, content) { if (error) { res.writeHead(500); res.end(); } else { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(content, 'utf-8'); } }); } }); // req on end function end } }).listen(port, host);
the part where I need help is marked with a symbol
here is my index.html:
<html> <body> <br> <br> please enter your password to start your download <br> <br> <form method="post" action="http://localhost:1337"> <input type="text" name="passwordpost" size="50"><br><br> <input type="submit" value="download" /> </form> </body> </html>
Do you know how to do this?
source share