backend-manager 5.0.8 → 5.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "5.0.8",
3
+ "version": "5.0.9",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -950,20 +950,41 @@ Manager.prototype.setupCustomServer = function (_library, options) {
950
950
 
951
951
  // Push function
952
952
  function _push(dir, isManager) {
953
- // Get all files
954
- glob('**/index.js', { cwd: dir })
953
+ // Get all files (index.js and method-specific files like get.js, post.js)
954
+ glob('**/*.js', { cwd: dir })
955
955
  .forEach((file) => {
956
+ const fileName = path.basename(file, '.js');
957
+ const dirName = path.dirname(file);
958
+
959
+ // Determine method and route name
960
+ let method = 'all'; // default to all methods
961
+ let routeName;
962
+
963
+ if (fileName === 'index') {
964
+ // Traditional index.js file: routes/restart/index.js -> restart
965
+ // Root index.js: routes/index.js -> '' (empty string for root path)
966
+ routeName = dirName === '.' ? '' : dirName;
967
+ } else if (['get', 'post', 'put', 'delete', 'patch', 'options', 'head'].includes(fileName.toLowerCase())) {
968
+ // Method-specific file: routes/restart/get.js -> restart (GET only)
969
+ method = fileName.toLowerCase();
970
+ routeName = dirName === '.' ? '' : dirName;
971
+ } else {
972
+ // Unknown pattern, skip
973
+ return;
974
+ }
975
+
956
976
  // Build the item
957
977
  const item = {
958
- name: file.replace('/index.js', ''),
978
+ name: routeName,
979
+ method: method,
959
980
  namespace: file,
960
981
  path: path.resolve(dir, file),
961
982
  dir: dir,
962
983
  isManager: isManager,
963
984
  }
964
985
 
965
- // If it exists in routes, replace it
966
- const existing = routes.findIndex(r => r.name === item.name);
986
+ // If it exists in routes with same name AND method, replace it
987
+ const existing = routes.findIndex(r => r.name === item.name && r.method === item.method);
967
988
  if (existing > -1) {
968
989
  routes[existing] = item;
969
990
  return;
@@ -991,51 +1012,29 @@ Manager.prototype.setupCustomServer = function (_library, options) {
991
1012
  const cors = self.libraries.cors;
992
1013
 
993
1014
  // Log
994
- if (options.log) {
995
- self.assistant.log(`Initializing route: ${file.name} @ ${file.path}`);
996
- }
1015
+ // if (options.log) {
1016
+ self.assistant.log(`Initializing route: ${file.method.toUpperCase()} /${file.name} @ ${file.path}`);
1017
+ // }
997
1018
 
998
- // Register the route
999
- app.all(`/${file.name}`, async (req, res) => {
1019
+ // Register the route with the appropriate HTTP method
1020
+ app[file.method](`/${file.name}`, async (req, res) => {
1000
1021
  return cors(req, res, async () => {
1001
- // self.Middleware(req, res).run(file.name, {schema: file.name})
1002
- self.Middleware(req, res).run(file.name, {
1003
- schema: file.name,
1022
+ // For root route (empty name), skip schema validation
1023
+ const middlewareOptions = {
1004
1024
  routesDir: file.isManager ? managerRoutesPath : customRoutesPath,
1005
1025
  schemasDir: file.isManager ? managerSchemasPath : customSchemasPath,
1006
- })
1026
+ };
1027
+
1028
+ // Only set schema if route name is not empty
1029
+ if (file.name) {
1030
+ middlewareOptions.schema = file.name;
1031
+ } else {
1032
+ middlewareOptions.setupSettings = false;
1033
+ }
1034
+
1035
+ self.Middleware(req, res).run(file.name, middlewareOptions)
1007
1036
  });
1008
1037
  })
1009
-
1010
- // app.all(`/${name}`, async (req, res) => {
1011
- // return cors(req, res, async () => {
1012
- // // Fix req/res
1013
- // req.body = req.body || {};
1014
- // req.query = Object.assign({}, req.query || {});
1015
-
1016
- // // Manager.Middleware(req, res).run('tools/screenshot', {schema: 'screenshot'})
1017
- // const handler = new (require(file.path))();
1018
- // const assistant = self.Assistant({req: req, res: res}, {functionName: name, functionType: 'http'});
1019
- // // const apiUser = await ApiManager.getUser(assistant);
1020
-
1021
- // // Set handler properties
1022
- // handler.Manager = self;
1023
- // handler.assistant = assistant;
1024
- // handler.apiUser = null;
1025
-
1026
- // // Log
1027
- // if (options.log) {
1028
- // self.assistant.log(`[Request] ${name} @ ${filepath}`, req.body, req.query);
1029
- // }
1030
-
1031
- // // Execute the route
1032
- // try {
1033
- // await handler.process(req, res);
1034
- // } catch (e) {
1035
- // assistant.respond(e, {code: e.code});
1036
- // }
1037
- // });
1038
- // })
1039
1038
  });
1040
1039
 
1041
1040
  // Run the server!
@@ -0,0 +1,27 @@
1
+ function Route() {
2
+ const self = this;
3
+
4
+ return self;
5
+ }
6
+
7
+ Route.prototype.main = async function (assistant) {
8
+ const self = this;
9
+
10
+ // Shortcuts
11
+ const Manager = assistant.Manager;
12
+ const usage = assistant.usage;
13
+ const user = assistant.usage.user;
14
+ const analytics = assistant.analytics;
15
+ const settings = assistant.settings;
16
+
17
+ // Get url
18
+ const url = Manager.config?.brand?.url;
19
+
20
+ // Log
21
+ assistant.log(`Route.main(): Executing route logic`, url);
22
+
23
+ // Redirect to Google
24
+ assistant.redirect(url);
25
+ };
26
+
27
+ module.exports = Route;
@@ -24,9 +24,9 @@ Route.prototype.main = async function (assistant) {
24
24
  });
25
25
 
26
26
  // Check for user authentication
27
- // if (!user.roles.admin) {
28
- // return assistant.respond(`Admin required`, {code: 401});;
29
- // }
27
+ if (!user.roles.admin) {
28
+ return assistant.respond(`Admin required`, {code: 401});;
29
+ }
30
30
 
31
31
  // Log
32
32
  assistant.log('Restarting...');
File without changes