split to public/private routes

This commit is contained in:
cyberdream 2022-08-19 23:12:06 +03:00
parent 7058a9baa6
commit 056d193d10
6 changed files with 105 additions and 0 deletions

25
src/private_api.ts Normal file
View File

@ -0,0 +1,25 @@
import express from "express";
import privateRoutes from "./routes/private_routes";
class PrivateApi{
public server;
constructor() {
this.server = express();
this.middlewares();
this.routes();
this.server.set('view engine', 'ejs');
this.server.use(express.static('public'));
}
middlewares() {
this.server.use(express.json());
}
routes() {
this.server.use(privateRoutes);
}
}
export default new PrivateApi().server;

30
src/public_api.ts Normal file
View File

@ -0,0 +1,30 @@
import express from "express";
import routes from "./routes/public_routes";
import minecraft_routes from "./routes/public/minecraft/minecraft_routes";
class PublicApi {
public server;
constructor() {
this.server = express();
this.middlewares();
this.routes();
this.server.set('view engine', 'ejs');
this.server.use(express.static('public'));
}
middlewares() {
this.server.use(express.json());
}
routes() {
//this.server.use(routes);
this.server.use('/minecraft', minecraft_routes)
}
}
export default new PublicApi().server;

View File

@ -0,0 +1,13 @@
import { Router } from "express";
const privateRoutes = Router();
privateRoutes.get("/", (req, res) => {
var data = {
content: 'Hi',
title: 'Example'
}
return res.render('dashboard');
});
export default privateRoutes;

View File

@ -0,0 +1,17 @@
import { Router } from "express";
import Minecraft from "../../../../minecraft/1.12.2/heliosDistribution"
const minecraft = new Minecraft //Is this right?
const routes = Router();
routes.get("/", (req, res) => {
return res.json({ message: "yes" });
});
routes.get("/distribution", (req, res) =>{
res.send(minecraft.generateDistribution())
});
export default routes;

View File

@ -0,0 +1,11 @@
import { Router } from "express";
import minecraft_1_12_2_routes from './1_12_2/routes'
const routes = Router();
routes.get("/", (req, res) => {
return res.json({ message: "Hello World" });
});
routes.use
routes.use('/1.12.2', minecraft_1_12_2_routes)
export default routes;

View File

@ -0,0 +1,9 @@
import { Router } from "express";
const publicRoutes = Router();
publicRoutes.get("/", (req, res) => {
return res.json("work")
});
export default publicRoutes;