Routes work as expected
This commit is contained in:
parent
d005aa3cc1
commit
b0b0be833a
@ -82,7 +82,7 @@ app.use('/admin', require('./routes/admin'))
|
||||
// GET localhost:8081/concept/list
|
||||
|
||||
const pluginData = pluginManager.init();
|
||||
app.use('/', pluginData.router);
|
||||
app.use('/plugins', pluginData.router);
|
||||
|
||||
// SETUP IO
|
||||
require('./io/campaign')(socket.getIo());
|
||||
|
@ -11,14 +11,16 @@ const router = express.Router();
|
||||
class BackendApi {
|
||||
#_plugin;
|
||||
#_router;
|
||||
#_expressRouter;
|
||||
|
||||
/**
|
||||
* This object is already created for you
|
||||
* @param {plugin} Plugin instance
|
||||
*/
|
||||
constructor(plugin){
|
||||
constructor(plugin, router){
|
||||
this.#_plugin = plugin;
|
||||
this.#_router = new BackendRouter(`/plugin/${plugin.package}`);
|
||||
this.#_expressRouter = router;
|
||||
this.#_router = new BackendRouter(`plugin/${plugin.package}`, this.#_expressRouter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,7 +53,7 @@ class BackendApi {
|
||||
}
|
||||
|
||||
createModule(id){
|
||||
return new BackendModule(this.#_plugin, id);
|
||||
return new BackendModule(this.#_plugin, id, this.#_expressRouter);
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,9 +63,11 @@ class BackendApi {
|
||||
*/
|
||||
class BackendRouter {
|
||||
#_root;
|
||||
#_expressRouter
|
||||
|
||||
constructor(path){
|
||||
this.#_root = `plugins/${path}`;
|
||||
constructor(path, expressRouter){
|
||||
this.#_root = `/${path}`;
|
||||
this.#_expressRouter = expressRouter;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +75,7 @@ class BackendRouter {
|
||||
* @param {String} route
|
||||
*/
|
||||
get(route, callback){
|
||||
router.get(this.#_root + route, callback);
|
||||
this.#_expressRouter.get(this.#_root + route, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +83,7 @@ class BackendRouter {
|
||||
*
|
||||
*/
|
||||
post(route, callback){
|
||||
router.post(this.#_root + route, callback);
|
||||
this.#_expressRouter.post(this.#_root + route, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +91,7 @@ class BackendRouter {
|
||||
*
|
||||
*/
|
||||
put(route, callback){
|
||||
router.put(this.#_root + route, callback);
|
||||
this.#_expressRouter.put(this.#_root + route, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +99,7 @@ class BackendRouter {
|
||||
*
|
||||
*/
|
||||
delete(route, callback){
|
||||
router.delete(this.#_root + route, callback);
|
||||
this.#_expressRouter.delete(this.#_root + route, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,10 +123,10 @@ class BackendModule {
|
||||
#_id;
|
||||
#_router;
|
||||
|
||||
constructor(plugin, id){
|
||||
constructor(plugin, id, expressRouter){
|
||||
this.#_plugin = plugin;
|
||||
this.#_id = id;
|
||||
this.#_router = new BackendRouter(`/module/${plugin.package}/${id}`)
|
||||
this.#_router = new BackendRouter(`module/${plugin.package}/${id}`, expressRouter)
|
||||
}
|
||||
|
||||
get router(){
|
||||
|
@ -2,7 +2,9 @@ const fs = require('fs');
|
||||
const path = require('path')
|
||||
const BackendApi = require('./api').BackendApi
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const router = express.Router({
|
||||
mergeParams: true
|
||||
});
|
||||
|
||||
const basePath = path.resolve(__dirname, '../')
|
||||
console.log(basePath)
|
||||
@ -27,13 +29,10 @@ function init(){
|
||||
|
||||
// Execute main
|
||||
Object.keys(plugins).forEach(k => {
|
||||
let pluginApi = new BackendApi(plugins[k].info);
|
||||
let pluginApi = new BackendApi(plugins[k].info, router);
|
||||
plugins[k].payload.Main(pluginApi);
|
||||
router.use(pluginApi._router);
|
||||
});
|
||||
|
||||
|
||||
|
||||
return {
|
||||
router
|
||||
}
|
||||
|
@ -26,8 +26,11 @@ LoadUser();
|
||||
|
||||
SetEmitter(emitter);
|
||||
|
||||
|
||||
async function DisplayFirstWindow(){
|
||||
if(GetUser()){
|
||||
|
||||
Server().get('/plugins/module/dnd-5e/dnd-5e/testing').then(res => {})
|
||||
CreateWindow('main_menu');
|
||||
return;
|
||||
}
|
||||
@ -47,6 +50,7 @@ async function DisplayFirstWindow(){
|
||||
}
|
||||
DisplayToast("red", t('register-account.setup.invalid-link'));
|
||||
CreateWindow('login');
|
||||
|
||||
});
|
||||
} else {
|
||||
if(await HasAdmin()){
|
||||
|
@ -11,16 +11,26 @@ function Main(api){
|
||||
let dndModule = Api.createModule('dnd-5e');
|
||||
|
||||
let itemModel = Api.createModel("item", {
|
||||
name: { type: "String", required: true, default: "New Concept"},
|
||||
type: { type: "String", required: true, default: "Concept" },
|
||||
name: { type: "String", required: true, default: "New item"},
|
||||
type: { type: "String", required: true, default: "Item" },
|
||||
info: { type: "Object" }, // For preview only
|
||||
data: { type: "Object" }, // Advanced item
|
||||
book: { type: "ObjectId", ref: "Book"},
|
||||
campaign: { type: "ObjectId", ref: "Campaign"},
|
||||
});
|
||||
|
||||
dndModule.router.get('/test', (req, res) => {
|
||||
dndModule.router.get('/testing', (req, res) => {
|
||||
/*
|
||||
let item = itemModel.create({
|
||||
name: "Test item!",
|
||||
type: "The test item"
|
||||
})
|
||||
*/
|
||||
|
||||
console.log("FUNCIONA!!!!");
|
||||
res.json({
|
||||
status: "ok"
|
||||
})
|
||||
})
|
||||
|
||||
// Api.router.createModelRoutes(itemModel, 'item');
|
||||
|
Loading…
Reference in New Issue
Block a user