started working on routing
This commit is contained in:
parent
1327813462
commit
b2989becd3
4
.gitignore
vendored
4
.gitignore
vendored
@ -88,7 +88,3 @@ sw.*
|
|||||||
|
|
||||||
# Vim swap files
|
# Vim swap files
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
# db file
|
|
||||||
db.json
|
|
||||||
pass
|
|
46
api/index.js
46
api/index.js
@ -1,22 +1,36 @@
|
|||||||
const express = require("express");
|
const express = require("express")
|
||||||
const {gimmeToken} = require("./util.js")
|
const {gimmeToken} = require("./util.js")
|
||||||
const { MongoClient } = require("mongodb");
|
const { MongoClient } = require("mongodb")
|
||||||
require("dotenv").config()
|
require("dotenv").config()
|
||||||
|
|
||||||
const app = express();
|
// routes
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.urlencoded({ extended: false }));
|
|
||||||
|
|
||||||
const client = new MongoClient(process.env.DATABASE);
|
|
||||||
const PASS = process.env.PASS
|
|
||||||
let TOKEN = gimmeToken();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* error: 0 -> no error
|
* error: 0 -> no error
|
||||||
* error: 1 -> parameter error
|
* error: 1 -> parameter error
|
||||||
* error: 2 -> auth error
|
* error: 2 -> auth error
|
||||||
* error: 3 -> not found error
|
* error: 3 -> not found error
|
||||||
*/
|
*/
|
||||||
|
const resources = require("./routes/resources.js")
|
||||||
|
const projects = require("./routes/projects.js")
|
||||||
|
const blog = require("./routes/blog.js")
|
||||||
|
const auth = require("./routes/auth.js")
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
app.use(express.json())
|
||||||
|
app.use(express.urlencoded({ extended: false }));
|
||||||
|
app.use("/resources", resources)
|
||||||
|
app.use("/projects", projects)
|
||||||
|
app.use("/blog", blog)
|
||||||
|
app.use("/auth", auth)
|
||||||
|
|
||||||
|
const db = new MongoClient(process.env.DATABASE);
|
||||||
|
const PASS = process.env.PASS
|
||||||
|
let TOKEN = gimmeToken();
|
||||||
|
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
req.db = db;
|
||||||
|
next();
|
||||||
|
})
|
||||||
|
|
||||||
// PATH: /api/login
|
// PATH: /api/login
|
||||||
// METHOD: GET
|
// METHOD: GET
|
||||||
@ -129,6 +143,18 @@ app.get("/get_resources", async (req, res) => {
|
|||||||
res.json({error: 0, resources:array})
|
res.json({error: 0, resources:array})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// PATH: /api/get_resources
|
||||||
|
// METHOD: GET
|
||||||
|
// PARAMETERS: NONE
|
||||||
|
app.get("/get_resources", async (req, res) => {
|
||||||
|
await client.connect()
|
||||||
|
const db = await client.db("ngn13")
|
||||||
|
const col = await db.collection("resources")
|
||||||
|
const array = await col.find().toArray()
|
||||||
|
await client.close()
|
||||||
|
res.json({error: 0, resources:array})
|
||||||
|
});
|
||||||
|
|
||||||
// PATH: /api/add_post
|
// PATH: /api/add_post
|
||||||
// METHOD: POST
|
// METHOD: POST
|
||||||
// PARAMETERS: token, title, author, content
|
// PARAMETERS: token, title, author, content
|
||||||
|
12
api/routes/resources.js
Normal file
12
api/routes/resources.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const express = require("express")
|
||||||
|
const resources = express.Router()
|
||||||
|
|
||||||
|
resources.get("/get", async (req,res)=>{
|
||||||
|
await req.db.connect()
|
||||||
|
const col = await req.db.collection("ngn13")
|
||||||
|
const results = col.find().limit(10).toArray()
|
||||||
|
await req.db.close()
|
||||||
|
res.json({ error: 0, resources: results })
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = resources
|
@ -30,8 +30,8 @@ main {
|
|||||||
padding: 40px;
|
padding: 40px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: .4s;
|
transition: .4s;
|
||||||
height: 13%;
|
height: 100px;
|
||||||
width: 27%;
|
width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
main:hover{
|
main:hover{
|
||||||
@ -56,7 +56,7 @@ h2{
|
|||||||
|
|
||||||
@media only screen and (max-width: 1121px) {
|
@media only screen and (max-width: 1121px) {
|
||||||
main{
|
main{
|
||||||
width: auto;
|
width: 80%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
@ -15,6 +15,7 @@ div{
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 30px;
|
gap: 30px;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "my-website",
|
"name": "my-website",
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nuxt",
|
"dev": "nuxt",
|
||||||
|
@ -29,15 +29,17 @@
|
|||||||
<br>
|
<br>
|
||||||
<a href="https://github.com/ngn13"><i class='bx bxl-github'></i> Github</a>
|
<a href="https://github.com/ngn13"><i class='bx bxl-github'></i> Github</a>
|
||||||
<br>
|
<br>
|
||||||
|
<a href="https://mastodon.social/@ngn"><i class='bx bxl-mastodon'></i> Mastodon</a>
|
||||||
|
<br>
|
||||||
<a href="mailto:ngn13proton@proton.me"><i class='bx bxs-envelope'></i> Mail</a>
|
<a href="mailto:ngn13proton@proton.me"><i class='bx bxs-envelope'></i> Mail</a>
|
||||||
<br>
|
<br>
|
||||||
<h2>or private message me on </h2>
|
<h2>or private message me on matrix:</h2>
|
||||||
<a><i>[matrix]</i> @ngn:matrix.ngn13.fun</a>
|
<a><i>[matrix]</i> @ngn:matrix.ngn13.fun</a>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
<Logout v-if="logged"/>
|
<Logout v-if="logged"/>
|
||||||
<div class="version">
|
<div class="version">
|
||||||
<p>v2.2</p>
|
<p>v2.3</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user