-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a functionality to automatically detect the ipv4 address of the device
- Loading branch information
Showing
58 changed files
with
7,984 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
var express = require('express'); | ||
var qrTerminal = require('qrcode-terminal'); | ||
var chalk = require('chalk'); | ||
var fs = require('fs'); | ||
var localIpV4Address = require('local-ipv4-address'); | ||
|
||
var misc = require("./lib/misc.js"); | ||
var constants = require("./lib/constants.js"); | ||
|
||
var app = express(); | ||
|
||
const port = 3000 || process.env.PORT; | ||
const pathInitial = __dirname + "/"; | ||
var pathTotal = pathInitial + process.argv[2]; | ||
|
||
var ipv4 = constants.IPv4; | ||
var ipv4 = "http://192.168.1.2:3000"; | ||
|
||
app.listen(port, (req,res) => { | ||
console.log("Server is live"); | ||
localIpV4Address().then(function(ipAddress){ | ||
ipv4 = ipAddress; | ||
}); | ||
|
||
|
||
if(process.argv.length != 3) { | ||
console.log(chalk.red(":/ Something's missing in the arguments")); | ||
console.log(chalk.green("It should be something like node index.js i_am_so_great.pdf")); | ||
process.exit(0); | ||
} | ||
|
||
if(!fs.existsSync(pathTotal)) { | ||
console.log(chalk.red("The file does not exist, Please check the file path again")); | ||
} | ||
else { | ||
|
||
app.listen(port, (req,res) => { | ||
//console.log("Server is live"); | ||
misc.header(); | ||
qrTerminal.generate(ipv4); | ||
|
||
}); | ||
|
||
app.get('/', (req,res) => { | ||
console.log("A GET req to the server was recieved"); | ||
res.sendFile(__dirname + "/files_to_send" + "/" + process.argv[2]); | ||
console.log(`A download was observed from ${req.ip}`); | ||
res.sendFile(pathInitial + process.argv[2]); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
module.exports = { | ||
owner: "Sagar", | ||
IPv4: "http://192.168.1.2:3000" | ||
owner: "Sagar" | ||
} | ||
|
||
//A lot to be added :D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.