-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakub Węglarek
committed
Feb 2, 2021
1 parent
6fc3015
commit 06328fe
Showing
9 changed files
with
69 additions
and
24 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const formatSubdomains = require("./formatSubdomains.js"); | ||
module.exports = request => `${request.protocol}://${formatSubdomains(request)}${request.hostname}${request.originalUrl}`; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const time = require("./time.js"); | ||
const formatLink = require("./formatLink.js"); | ||
module.exports = request => `${time()} - ${request.ip.slice(7)} (${request.method}: ${formatLink(request)})`; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = request => { | ||
let response = ""; | ||
request.subdomains.forEach(subdomain => response += `${subdomain}.`); | ||
return response; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const formatLog = require("../functions/formatLog.js"); | ||
const fs = require("fs"); | ||
module.exports = request => fs.appendFile("log/log.log", `${formatLog(request)}\n`, { | ||
encoding: "utf-8" | ||
}, error => error); |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = () => { | ||
let now = new Date(); | ||
let hour = now.getHours(); | ||
if (hour < 10) { | ||
hour = `0${hour}`; | ||
} | ||
let minute = now.getMinutes(); | ||
if (minute < 10) { | ||
minute = `0${minute}`; | ||
} | ||
let second = now.getSeconds(); | ||
if (second < 10) { | ||
second = `0${second}`; | ||
} | ||
let day = now.getDate(); | ||
if (day < 10) { | ||
day = `0${day}`; | ||
} | ||
let month = now.getMonth() + 1; | ||
if (month < 10) { | ||
month = `0${month}`; | ||
} | ||
let year = now.getFullYear(); | ||
return `${hour}:${minute}:${second} ${day}.${month}.${year}.`; | ||
} |
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,33 +1,37 @@ | ||
const config = require("../config/config.json"); | ||
const sendResponse = require("../functions/sendResponse.js"); | ||
const log = require("../functions/log.js"); | ||
const config = require("../config/config.json"); | ||
module.exports = (request, response) => { | ||
response.set({ | ||
"Access-Control-Allow-Origin": "*" | ||
}); | ||
if (!request.query.min) sendResponse(response, 400); | ||
else if (!request.query.max) sendResponse(response, 400); | ||
else if (isNaN(request.query.min)) sendResponse(response, 400); | ||
else if (isNaN(request.query.max)) sendResponse(response, 400); | ||
else if (request.query.min < 0) sendResponse(response, 416); | ||
else if (request.query.min > request.query.max) sendResponse(response, 416); | ||
else if (!request.query.num) { | ||
const min = request.query.min; | ||
const max = request.query.max; | ||
const random = Math.floor(Math.random() * (max - min + 1) + min); | ||
response.status(200).end(random.toString()); | ||
} else { | ||
if (isNaN(request.query.num)) sendResponse(response, 400); | ||
else if (request.query.num < 1) sendResponse(response, 416); | ||
else if (request.query.num > config.numLimit) sendResponse(response, 416); | ||
else { | ||
if (log(request)) sendResponse(response, 500); | ||
else { | ||
if (!request.query.min) sendResponse(response, 400); | ||
else if (!request.query.max) sendResponse(response, 400); | ||
else if (isNaN(request.query.min)) sendResponse(response, 400); | ||
else if (isNaN(request.query.max)) sendResponse(response, 400); | ||
else if (request.query.min < 0) sendResponse(response, 416); | ||
else if (request.query.min > request.query.max) sendResponse(response, 416); | ||
else if (!request.query.num) { | ||
const min = request.query.min; | ||
const max = request.query.max; | ||
const numbers = []; | ||
for (let i = 0; i < request.query.num; i++) { | ||
const random = Math.floor(Math.random() * (max - min + 1) + min); | ||
numbers.push(random); | ||
const random = Math.floor(Math.random() * (max - min + 1) + min); | ||
response.status(200).end(random.toString()); | ||
} else { | ||
if (isNaN(request.query.num)) sendResponse(response, 400); | ||
else if (request.query.num < 1) sendResponse(response, 416); | ||
else if (request.query.num > config.numLimit) sendResponse(response, 416); | ||
else { | ||
const min = request.query.min; | ||
const max = request.query.max; | ||
const numbers = []; | ||
for (let i = 0; i < request.query.num; i++) { | ||
const random = Math.floor(Math.random() * (max - min + 1) + min); | ||
numbers.push(random); | ||
} | ||
response.status(200).end(JSON.stringify(numbers)); | ||
} | ||
response.status(200).end(JSON.stringify(numbers)); | ||
} | ||
} | ||
} |
Empty file.
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