Skip to content

Commit f0bc197

Browse files
committed
Minor changes for env
1 parent 58375b9 commit f0bc197

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

app.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,64 @@ app.use(bodyParser.json());
1616
app.use(cors());
1717

1818
mongoose
19-
.connect(
20-
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0-jwfcs.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority`,
21-
{
22-
useNewUrlParser: true,
23-
useUnifiedTopology: true,
24-
useCreateIndex: true,
25-
}
26-
)
27-
.then(() => {
28-
console.log("MongoDb connected.....");
29-
})
30-
.catch((err) => {
31-
console.log("Cannot connect to db due to " + err);
32-
});
19+
.connect(
20+
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0-jwfcs.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority`,
21+
{
22+
useNewUrlParser: true,
23+
useUnifiedTopology: true,
24+
useCreateIndex: true,
25+
}
26+
)
27+
.then(() => {
28+
console.log("MongoDb connected.....");
29+
})
30+
.catch((err) => {
31+
console.log("Cannot connect to db due to " + err);
32+
});
3333

3434
app.use("/api/urls", url);
3535
app.use("/api/register", users);
3636
app.use("/api/login", auth);
3737

3838
app.get("/:code", async (req, res) => {
39-
try {
40-
const url = await Url.findOne({ code: req.params.code });
39+
try {
40+
const url = await Url.findOne({ code: req.params.code });
4141

42-
if (url) {
43-
if (
44-
url.lastDate &&
45-
url.lastDate.toISOString() < new Date().toISOString()
46-
) {
47-
const user = await User.findById(url.creator);
42+
if (url) {
43+
if (
44+
url.lastDate &&
45+
url.lastDate.toISOString() < new Date().toISOString()
46+
) {
47+
const user = await User.findById(url.creator);
4848

49-
for (let i = 0; i < user.shortenedUrl.length; i++) {
50-
if (user.shortenedUrl[i].toString() === id) {
51-
user.shortenedUrl.splice(i, 1);
52-
break;
53-
}
54-
}
55-
await user.save();
56-
await url.deleteOne();
57-
return res
58-
.status(404)
59-
.json({ msg: "This Compress URL does not exist any more!" });
60-
}
61-
if (!url.status) {
62-
return res
63-
.status(200)
64-
.json({ msg: "This url is temporarily out of service!" });
65-
}
49+
for (let i = 0; i < user.shortenedUrl.length; i++) {
50+
if (user.shortenedUrl[i].toString() === id) {
51+
user.shortenedUrl.splice(i, 1);
52+
break;
53+
}
54+
}
55+
await user.save();
56+
await url.deleteOne();
57+
return res
58+
.status(404)
59+
.json({ msg: "This Compress URL does not exist any more!" });
60+
}
61+
if (!url.status) {
62+
return res
63+
.status(200)
64+
.json({ msg: "This url is temporarily out of service!" });
65+
}
6666

67-
url.clicks = url.clicks + 1;
68-
url.save();
69-
return res.redirect(url.longUrl);
70-
} else {
71-
return res.status(404).json({ msg: "No Compressed URL Found" });
72-
}
73-
} catch (err) {
74-
console.log(err);
75-
res.status(500).json({ msg: "Internal Server Error" });
76-
}
67+
url.clicks = url.clicks + 1;
68+
url.save();
69+
return res.redirect(url.longUrl);
70+
} else {
71+
return res.status(404).json({ msg: "No Compressed URL Found" });
72+
}
73+
} catch (err) {
74+
console.log(err);
75+
res.status(500).json({ msg: "Internal Server Error" });
76+
}
7777
});
7878

7979
const port = process.env.PORT || 5000;

0 commit comments

Comments
 (0)