Untitled
unknown
javascript
2 years ago
1.4 kB
12
Indexable
// Initializing log
const { log } = require('console');
/*
* Ttiel: Uptime Monitoring Application
* Description: YouTube dekhe siktesi
* Author: Touhidul Islam
* Date: 6th April 2024
*/
// dependencies
const http = require('http');
const url = require('url');
const { StringDecoder } = require('string_decoder');
// app object-module scaffolding
const app = {};
// config
app.config = {
port: 2000,
};
// Server creation
app.createServer = () => {
const server = http.createServer(app.handleRqRes);
server.listen(app.config.port, () => {
log(`Listening Port ${app.config.port}`);
});
};
// handle req and res
app.handleRqRes = (req, res) => {
// Get URL and Parse it
const parseurl = url.parse(req.url, true);
const path = parseurl.pathname;
const trim_path = path.replace(/^\/+|\/+$/g, '');
const method = req.method.toLowerCase();
// log(parseurl.query);
// log(trim_path);
// log(method);
// log(req.headers);
const decoder = new StringDecoder('utf-8');
let realData = '';
req.on('data', (buffer) => {
realData += decoder.write(buffer);
});
res.on('end', () => {
realData += decoder.end();
log(realData);
res.end('Tota');
});
};
// start the server
app.createServer();
Editor is loading...
Leave a Comment