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