-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (39 loc) · 1.11 KB
/
app.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
const express=require("express");
const bodyParser = require("body-parser");
const app=express();
//--------------body-parser
app.use(bodyParser.urlencoded({extended:true}));
var links=new Map();
var count=1;
var sameFlag=0;
app.get("/",(req,res)=>{
//res.render("home.ejs");
res.render("main.ejs",{sameFlag:sameFlag});
});
app.post("/addLink",(req,res)=>{
var myLink=req.body.myLink;
//var ans="link"+count;
var ans=req.body.keyword;
if(myLink.length===0 || ans.length===0 ){
res.render("main.ejs",{sameFlag:sameFlag});
}
//count++;
if(links.has(ans)){
flag=1;
res.render("main.ejs",{sameFlag:sameFlag});
// alert("Fill every field!!");
}
links.set(ans,myLink);
ans="https://tothemoon.run.goorm.io/"+ans;
res.render("secondary.ejs",{ans:ans});
});
app.get("/:newLink",(req,res)=>{
var subLink=req.params.newLink;
var genLink=links.get(subLink);
//res.send("you get: "+genLink);
res.redirect(genLink);
});
//---------------------------------------------------------------------------------------------------------
app.listen(3000,()=>{
console.log("server listening on port 3000");
});