move some files into other folders and make some code neater
This commit is contained in:
parent
50a3564fd4
commit
4d61db3e5b
13 changed files with 1125 additions and 1189 deletions
|
@ -2,23 +2,21 @@ const User = require("../../models/User");
|
||||||
const Category = require("../../models/Category");
|
const Category = require("../../models/Category");
|
||||||
const Post = require("../../models/Post");
|
const Post = require("../../models/Post");
|
||||||
const config = require("../../config");
|
const config = require("../../config");
|
||||||
|
const { authenticateEndpoint } = require("./../../common/auth/authfunctions");
|
||||||
const { authenticateEndpoint } = require("./authfunctions");
|
|
||||||
|
|
||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const { body, param, validationResult } = require("express-validator");
|
const { body, param, validationResult } = require("express-validator");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
|
||||||
const app = express.Router();
|
|
||||||
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
|
|
||||||
|
|
||||||
const rateLimit = require("express-rate-limit");
|
const rateLimit = require("express-rate-limit");
|
||||||
|
|
||||||
|
const app = express.Router();
|
||||||
const createLimiter = rateLimit({
|
const createLimiter = rateLimit({
|
||||||
windowMs: 2 * 60 * 1000,
|
windowMs: 2 * 60 * 1000,
|
||||||
max: 10,
|
max: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
|
||||||
|
|
||||||
app.post("/category/create", [
|
app.post("/category/create", [
|
||||||
createLimiter,
|
createLimiter,
|
||||||
body("title").not().isEmpty().trim().isLength({ min: 3, max: 32 }).escape()
|
body("title").not().isEmpty().trim().isLength({ min: 3, max: 32 }).escape()
|
||||||
|
|
|
@ -2,7 +2,7 @@ const User = require("../../../models/User");
|
||||||
const secret = require("../../../secret");
|
const secret = require("../../../secret");
|
||||||
const config = require("../../../config");
|
const config = require("../../../config");
|
||||||
const Category = require("../../../models/Category");
|
const Category = require("../../../models/Category");
|
||||||
const RateLimiter = require("./ratelimiter");
|
const RateLimiter = require("../../../common/util/ratelimiter");
|
||||||
|
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
const siolib = require("socket.io");
|
const siolib = require("socket.io");
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
const User = require("../../models/User");
|
const User = require("../../models/User");
|
||||||
const config = require("../../config");
|
const config = require("../../config");
|
||||||
const secret = require("../../secret");
|
const secret = require("../../secret");
|
||||||
|
const { authenticateEndpoint } = require("./../../common/auth/authfunctions");
|
||||||
const { authenticateEndpoint } = require("./authfunctions");
|
|
||||||
|
|
||||||
// TODO: Might want to use something else (https://blog.benpri.me/blog/2019/01/13/why-you-shouldnt-be-using-bcrypt-and-scrypt/)
|
// TODO: Might want to use something else (https://blog.benpri.me/blog/2019/01/13/why-you-shouldnt-be-using-bcrypt-and-scrypt/)
|
||||||
const bcrypt = require("bcrypt");
|
const bcrypt = require("bcrypt");
|
||||||
|
@ -10,18 +9,17 @@ const mongoose = require("mongoose");
|
||||||
const { body, param, validationResult } = require("express-validator");
|
const { body, param, validationResult } = require("express-validator");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
|
|
||||||
const app = express.Router();
|
|
||||||
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
|
|
||||||
|
|
||||||
const rateLimit = require("express-rate-limit");
|
const rateLimit = require("express-rate-limit");
|
||||||
|
|
||||||
|
const app = express.Router();
|
||||||
const createAccountLimiter = rateLimit({
|
const createAccountLimiter = rateLimit({
|
||||||
windowMs: 60 * 60 * 1000, // 1 hour window
|
windowMs: 60 * 60 * 1000, // 1 hour window
|
||||||
max: 10, // start blocking after 5 requests
|
max: 10, // start blocking after 5 requests
|
||||||
message: "You are being rate limited"
|
message: "You are being rate limited"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
|
||||||
|
|
||||||
app.get("/account/create/info", async (req, res) => {
|
app.get("/account/create/info", async (req, res) => {
|
||||||
let requiresCode = false;
|
let requiresCode = false;
|
||||||
if (config.restrictions) {
|
if (config.restrictions) {
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
POST http://localhost:3000/api/v1/users/account/create
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"username": "test",
|
|
||||||
"password": "testtesttest",
|
|
||||||
"email": "test@test.test"
|
|
||||||
}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
POST http://localhost:3000/api/v1/users/token/create
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"username": "test",
|
|
||||||
"password": "testtesttest"
|
|
||||||
}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET http://localhost:3000/api/v1/users/current/info
|
|
||||||
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDA1MTA2MTEsImV4cCI6MTYwMDUyMTQxMX0.q85p94FLPR4fxZ4O5pmalEEjU9Hyr9js63u6LgoCQCw
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
POST http://localhost:3000/api/v1/content/category/create
|
|
||||||
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"title": "testing1"
|
|
||||||
}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
POST http://localhost:3000/api/v1/content/post/create
|
|
||||||
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"category": "5fb1ba3eb04f2b3356aa2e58",
|
|
||||||
"title": "Test title",
|
|
||||||
"body": "Test content!!!"
|
|
||||||
}
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET http://localhost:3000/api/v1/content/category/5fb1ba3eb04f2b3356aa2e58/info
|
|
||||||
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET http://localhost:3000/api/v1/content/category/list
|
|
||||||
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDA1MTA2MTEsImV4cCI6MTYwMDUyMTQxMX0.q85p94FLPR4fxZ4O5pmalEEjU9Hyr9js63u6LgoCQCw
|
|
||||||
Content-Type: application/json
|
|
|
@ -6,7 +6,7 @@ const cookieParser = require("cookie-parser");
|
||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
|
||||||
const { authenticateEndpoint } = require("./api/v1/authfunctions");
|
const { authenticateEndpoint } = require("./common/auth/authfunctions");
|
||||||
const GatewayServer = require("./api/v1/gateway/index");
|
const GatewayServer = require("./api/v1/gateway/index");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
@ -35,10 +35,6 @@ app.get("/", authenticateEndpoint((req, res) => {
|
||||||
res.redirect("/app.html");
|
res.redirect("/app.html");
|
||||||
}, "/auth.html"));
|
}, "/auth.html"));
|
||||||
|
|
||||||
app.get("/admin", (req, res) => {
|
|
||||||
res.send("Keanu chungus wholesome 100 reddit moment 😀i beat up a kid that said minecraft bad 😂and my doggo bit him so i gave him snaccos😉 and we watched pewdiepie together while in elon musk’s cyber truck 😳talking about how superior reddit memers are : “haha emojis bad” 😲i said and keanu reeves came outta nowhere and said “this is wholesome 100, updoot this wholesome boy” 😗so i got alot of updoots and edit: thanks for the gold kind stranger😣. but the kind stranger revealed himself to be baby yoda eating chiccy nuggies😨 and drinking choccy milk😎 so we went to the cinema to see our (communism funny) favorite movies avengers endgame😆 but then thor played fortnite and fortnite bad😡, so then i said “reality is often dissappointing” and then baby yoda replied r/unexpectedthanos and i replied by r/expectedthanos😖 for balance and then danny devito came to pick us up from the cinema😩 and all the insta normies and gay mods stood watching😵 ,as we,superior redditors went home with danny devito to suck on his magnum dong😫 but i said no homo and started sucking,not like those gay mods😮,then the next morning we woke up to MrBeast telling us to plant 69420 million trees😌, me, baby yoda and danny said nice, and then on our way to plant 69420 million trees😊 (nice) we saw a kid doing a tiktok so keanu reeves appeared and said “we have a kid to burn” and i replied “you’re breathtaking”😄 so i said “i need a weapon” and baby yoda gave me an RPG so i blew the kid (DESTRUCTION 100)😎 and posted it on r/memes and r/dankmemes and r/pewdiepiesubmissions and got 1000000000 updoots😘,i’m sure pewds will give me a big pp, then we shat on emoji users😂😂 and started dreaming about girls that will never like me😢 and posted a lie on r/teenagers about how i got a GF after my doggo died by the hands of fortnite players😳 so i exploited his death for updoots😜, but i watched the sunset with the wholesome gang😁 (keanu,danny,Mrbeast, pewds, spongebob,stefan karl , bob ross, steve irwin, baby yoda and other artists that reddit exploits them) [Everyone liked that] WHOLESOME 100 REDDIT 100🤡");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
console.error("[E] Internal server error", err);
|
console.error("[E] Internal server error", err);
|
||||||
res.status(500).json({ error: true, status: 500, message: "ERR_INTERNAL_SERVER_ERROR" });
|
res.status(500).json({ error: true, status: 500, message: "ERR_INTERNAL_SERVER_ERROR" });
|
||||||
|
|
2201
brainlet/package-lock.json
generated
Executable file → Normal file
2201
brainlet/package-lock.json
generated
Executable file → Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"name": "dictionar",
|
"name": "brainlet",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
|
@ -5,6 +5,6 @@ module.exports = {
|
||||||
// Set default values
|
// Set default values
|
||||||
// You shouldn't need to touch this for configuring this
|
// You shouldn't need to touch this for configuring this
|
||||||
if (module.exports.jwtPrivateKey === "KEY") {
|
if (module.exports.jwtPrivateKey === "KEY") {
|
||||||
console.error("[*] [config] jwtPrivateKey was not specified in secret.js. A randomly generated private key will be used instead");
|
console.error("[*] [config] jwtPrivateKey was not specified in secret.js. A randomly generated private key will be used instead.");
|
||||||
module.exports.jwtPrivateKey = require("crypto").randomBytes(129).toString("base64");
|
module.exports.jwtPrivateKey = require("crypto").randomBytes(129).toString("base64");
|
||||||
}
|
}
|
||||||
|
|
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"name": "brainlet",
|
|
||||||
"lockfileVersion": 2,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
{}
|
|
|
@ -50,7 +50,7 @@ You need to edit the config.js file in order to allow your domain to CORS, and m
|
||||||
## You should now be ready to go!
|
## You should now be ready to go!
|
||||||
Just run Brainlet with the command below:
|
Just run Brainlet with the command below:
|
||||||
```
|
```
|
||||||
node index.js
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
Afterwards, try going to [http://localhost:3005/auth.html](http://localhost:3005/auth.html) to visit the site, assuming default port config.
|
Afterwards, try going to [http://localhost:3005/auth.html](http://localhost:3005/auth.html) to visit the site, assuming default port config.
|
||||||
|
|
Reference in a new issue