Skip to content

Commit

Permalink
feat: redirect to local custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
saurbhmehtamelio committed Sep 26, 2024
1 parent 2e16f1a commit 89f676f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ app.use(express.json())

const dnsService = new LocalDNSService()

app.get("/all", async (_req, res) => {
try{
const allDomains = await dnsService.getAllDomainsWithPort()
return res.status(200).json({
domains: allDomains
})
}
catch(err: any){
return res.status(500).json({
err: err.message
})
}
})

app.get("*", async function(req: Request, res){
const hostname = req.hostname
const domainNameFound = await dnsService.checkDomain(hostname)

const allDomains = await dnsService.getAllDomainsWithPort()
const matchedDomain = allDomains.find(d => d.name.toLowerCase() === hostname.toLowerCase())

if(matchedDomain){
return res.redirect("http://localhost:" + matchedDomain.port)
}
else{
res.status(404).json({
error: "Domain not found."
})
}

// res.send("Hello from locally running DNS server 👋.No matter where you Go I will follow")

if(domainNameFound){
Expand Down

0 comments on commit 89f676f

Please sign in to comment.