new routes done + fixed blog
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const express = require("express");
|
||||
const { MongoClient } = require("mongodb");
|
||||
const { makeID } = require("../api/util.js")
|
||||
require("dotenv").config()
|
||||
|
||||
const app = express();
|
||||
@@ -10,20 +11,20 @@ const client = new MongoClient(process.env.DATABASE);
|
||||
|
||||
app.get("/:id", async (req,res)=>{
|
||||
const id = req.params.id
|
||||
|
||||
|
||||
await client.connect()
|
||||
const db = await client.db("ngn13")
|
||||
const col = await db.collection("projects")
|
||||
const projects = await col.find().toArray()
|
||||
|
||||
|
||||
console.log(projects)
|
||||
|
||||
for(let i=0; i<projects.length;i++){
|
||||
if(projects[i]["name"].toLowerCase().replaceAll(" ", "")===id){
|
||||
if(makeID(projects[i]["name"])===id){
|
||||
res.redirect(projects[i]["url"])
|
||||
await col.updateOne({name:projects[i]["name"]}, {"$set": {"click": projects[i]["click"]+1}})
|
||||
await col.updateOne({ name: projects[i]["name"] }, { "$set":
|
||||
{ "click": projects[i]["click"]+1 }})
|
||||
return await client.close()
|
||||
|
||||
}
|
||||
}
|
||||
await client.close()
|
||||
@@ -33,4 +34,4 @@ app.get("/:id", async (req,res)=>{
|
||||
export default {
|
||||
path: "/l",
|
||||
handler: app,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user