From 29158ed6f0758f9c53c159a5f6a6eef3156298b6 Mon Sep 17 00:00:00 2001
From: Shubhadeep <41886925+shubha161@users.noreply.github.com>
Date: Sun, 12 Jul 2020 17:54:48 +0530
Subject: [PATCH] Add files via upload
---
index.html | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
index.js | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
create mode 100644 index.html
create mode 100644 index.js
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..de69f9f
--- /dev/null
+++ b/index.html
@@ -0,0 +1,54 @@
+
+
+
+
+ See Dogs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..3fbee42
--- /dev/null
+++ b/index.js
@@ -0,0 +1,41 @@
+const server = require("http").createServer();
+const fs = require("fs");
+const superagent = require('superagent');
+
+
+let temp = fs.readFileSync(`${__dirname}/index.html`, "utf-8");
+
+const Replace = (tmp, data) => {
+ let output = tmp.replace(/{%IMAGE%}/g, data);
+ return output;
+}
+
+server.on("request", (req, res) => {
+ const path = req.url;
+ if (path === "/" || path === "/home" || path === "/index") {
+ res.writeHead(200);
+ res.end("Hello")
+
+ } else if (path === "/dogs") {
+ res.writeHead(200, {
+ "Content-type": "text/html"
+ });
+
+ superagent
+ .get("https://dog.ceo/api/breeds/image/random")
+ .end((err, img) => {
+
+ let page = Replace(temp, img.body.message);
+ res.end(page)
+
+ })
+
+ } else {
+ res.writeHead(404);
+ res.end("page not found")
+
+ }
+
+})
+
+server.listen()
\ No newline at end of file