-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.min.js
1 lines (1 loc) · 1.42 KB
/
server.min.js
1
"use strict";const express=require("express"),morgan=require("morgan"),http=require("http"),https=require("https"),path=require("path"),axios=require("axios"),bodyParser=require("body-parser"),compression=require("compression"),helmet=require("helmet"),app=express(),port=process.env.PORT||8080;app.use(morgan("combined")),app.use(helmet()),app.use(bodyParser.json()),app.use(bodyParser.text({type:"text/xml"})),app.use(express.static(path.join(__dirname,"assets"))),app.use(compression()),app.listen(port,()=>{console.log(`Our site is hosted on ${port}! If you donot know to open just go to browser and type (localhost:${port})`)}),app.get("/favicon.ico",(req,res)=>{res.sendFile(path.join(__dirname,"assets","catchup.png"))}),app.get("/",(req,res)=>{res.sendFile(path.join(__dirname,"index.min.html"))}),app.get("/hackernews",(req,res)=>{axios.get("https://hnrss.org/newest.jsonfeed",{responseType:"json"}).then(resp=>{res.send(resp.data)}).catch(err=>{console.log(`\n\n ${err} \n\n`),res.status(500).send(err)})}),app.get("/hackernewsTop",(req,res)=>{axios.get("https://hnrss.org/newest.jsonfeed",{responseType:"json"}).then(resp=>{res.send(resp.data)}).catch(err=>{console.log(`\n\n ${err} \n\n`),res.status(500).send(err)})}),app.get("/hackerearth",(req,res)=>{axios.get("http://engineering.hackerearth.com/atom.xml",{responseType:"document"}).then(resp=>{res.send(resp.data)}).catch(err=>{console.log(`\n\n ${err} \n\n`),res.status(500).send(err)})});