-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (50 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import express from "express";
import axios from "axios";
import bodyParser from "body-parser";
const port = 3000;
const app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
var username = "";
var password = "";
// function logger(req,res,next){
// console.log("body is",req.body);
// username = req.body.type;
// next();
// }
// app.use(logger);
app.get("/", (req, res) => {
res.render("index.ejs", { imageUrl: "Waiting for the data..." });
});
app.post("/res", async (req, res) => {
console.log(req.body);
console.log(req.body.password);
const username = req.body.username;
const password = req.body.password;
if ((username === "suraj" && password === "hello")) {
try {
const result = await axios.get(
"https://api.thecatapi.com/v1/images/search",
{
headers: {
"x-api-key":
"live_2LQg7Mt5yWMobgjNyGrUV2l5pMij5IlBQAXVBQde1EmHDAZxnOl60nL9VeIPJc8K",
},
}
);
console.log(result.data);
const imageUrl= result.data[0].url;
res.render("index.ejs", { imageUrl });
} catch (error) {
console.log(error);
}
}else{
res.redirect('/')
}
});
// app.get("/res", async (req, res) => {
// // console.log("body is",req.body["username"]);
// });
app.listen(port, () => {
console.log(`server running at ${port}`);
});