@l10nmonster/server 3.0.0-alpha.13 → 3.0.0-alpha.15

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.
Files changed (2) hide show
  1. package/index.js +18 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -27,10 +27,13 @@ import { setupChannelRoutes } from './routes/sources.js';
27
27
  import { setupTmRoutes } from './routes/tm.js';
28
28
  import { setupProviderRoute } from './routes/providers.js';
29
29
  import { setupDispatcherRoutes } from './routes/dispatcher.js';
30
+ import { logVerbose } from '@l10nmonster/core';
30
31
 
31
32
  const serverPackage = JSON.parse(readFileSync(path.join(import.meta.dirname, 'package.json'), 'utf-8'));
32
33
 
33
- export default class serve {
34
+ export default class ServeAction {
35
+ static extensions = {};
36
+ static name = 'serve';
34
37
  static help = {
35
38
  description: 'starts the L10n Monster server.',
36
39
  options: [
@@ -41,6 +44,10 @@ export default class serve {
41
44
  ]
42
45
  };
43
46
 
47
+ static registerExtension(name, routeMaker) {
48
+ ServeAction.extensions[name] = routeMaker;
49
+ }
50
+
44
51
  static async action(mm, options) {
45
52
  const port = options.port ?? 9691;
46
53
  const host = options.host; // undefined means listen on all interfaces
@@ -64,6 +71,16 @@ export default class serve {
64
71
  // Mount the API router under the /api prefix
65
72
  app.use('/api', apiRouter);
66
73
 
74
+ for (const [name, routeMaker] of Object.entries(ServeAction.extensions)) {
75
+ const extensionRouter = express.Router();
76
+ const routes = routeMaker(mm);
77
+ for (const [method, path, handler] of routes) {
78
+ extensionRouter[method](path, handler);
79
+ }
80
+ app.use(`/api/ext/${name}`, extensionRouter);
81
+ logVerbose`Mounted extension ${name} at /api/ext/${name}`;
82
+ }
83
+
67
84
  // API 404 handler - must come before the UI catch-all
68
85
  app.use('/api/*splat', (req, res) => {
69
86
  res.status(404).json({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@l10nmonster/server",
3
- "version": "3.0.0-alpha.13",
3
+ "version": "3.0.0-alpha.15",
4
4
  "description": "L10n Monster Manager",
5
5
  "type": "module",
6
6
  "main": "index.js",