Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
/node_modules
npm-debug.log
.DS_Store
/*.env
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web:node app.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://github.com/githubcrce/Url-Shortener"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/githubcrce/Url-Shortener">View Demo</a>
<a href="https://pure-thicket-55317.herokuapp.com/">View Demo</a>
·
<a href="https://github.com/githubcrce/Url-Shortenerissues/new/choose">Report Bug</a>
·
Expand Down
10 changes: 6 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ const app = express()
mongoose.connect('mongodb://localhost/urlShortener',{
useNewUrlParser: true,
useUnifiedTopology: true
})
}).then(data=>{
console.log("DB connected");
}).catch(err=>console.log(err))

app.set('view engine', 'ejs')
app.use(express.urlencoded({ extended: false }))

app.get('/', async (req, res) => {
const shortUrls = await ShortUrl.find()
const shortUrls = await ShortUrl.find().catch(err=>console.log(err))
res.render('index', { shortUrls: shortUrls })
})

app.post('/shortUrls', async (req, res) => {
await ShortUrl.create({ full: req.body.fullUrl })
await ShortUrl.create({ full: req.body.fullUrl }).catch(err=>console.log(err))
res.redirect('/')
})

app.get('/:shortUrl', async(req, res) =>{
const shortUrl = await ShortUrl.findOne({ short: req.params.shortUrl })
const shortUrl = await ShortUrl.findOne({ short: req.params.shortUrl }).catch(err=>console.log(err))
if(shortUrl == null) return res.sendStatus(404)

shortUrl.clicks++
Expand Down