@jbrowse/cli 3.6.3 → 3.6.5

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.
@@ -102,7 +102,7 @@ function validateAndExtractParams({ req, key, baseDir, outFile, }) {
102
102
  /**
103
103
  * Sets up the API routes for the server
104
104
  */
105
- function setupRoutes({ app, baseDir, outFile, key, }) {
105
+ function setupRoutes({ app, baseDir, outFile, key, serverRef, }) {
106
106
  // Root route
107
107
  app.get('/', (_req, res) => {
108
108
  res.setHeader('Content-Type', 'text/plain');
@@ -157,6 +157,24 @@ function setupRoutes({ app, baseDir, outFile, key, }) {
157
157
  res.send('Error: Failed to read config');
158
158
  }
159
159
  });
160
+ // Shutdown route for testing
161
+ app.post('/shutdown', (req, res) => {
162
+ const { body } = req;
163
+ const adminKey = body?.adminKey;
164
+ if (adminKey !== key) {
165
+ res.status(401).setHeader('Content-Type', 'text/plain');
166
+ res.send('Error: Invalid admin key');
167
+ return;
168
+ }
169
+ res.setHeader('Content-Type', 'text/plain');
170
+ res.send('Server shutting down');
171
+ // Shutdown the server after sending response
172
+ setImmediate(() => {
173
+ if (serverRef.current) {
174
+ serverRef.current.close();
175
+ }
176
+ });
177
+ });
160
178
  }
161
179
  /**
162
180
  * Sets up the Express server with routes
@@ -190,14 +208,16 @@ function setupServer({ baseDir, outFile, bodySizeLimit, }) {
190
208
  console.error(`Failed to write admin key to ${keyPath}:`, error.message);
191
209
  // Continue anyway, as this is not critical
192
210
  }
211
+ // Create server reference for shutdown route
212
+ const serverRef = { current: null };
193
213
  // Set up routes
194
- setupRoutes({ app, baseDir, outFile, key });
195
- return { app, key, keyPath };
214
+ setupRoutes({ app, baseDir, outFile, key, serverRef });
215
+ return { app, key, keyPath, serverRef };
196
216
  }
197
217
  /**
198
218
  * Starts the server and sets up shutdown handlers
199
219
  */
200
- function startServer({ app, port, key, outFile, keyPath, }) {
220
+ function startServer({ app, port, key, outFile, keyPath, serverRef, }) {
201
221
  // Start the server
202
222
  const server = app.listen(port, () => {
203
223
  console.log(`Admin server started on port ${port}\n\n` +
@@ -207,6 +227,8 @@ function startServer({ app, port, key, outFile, keyPath, }) {
207
227
  `Config file: ${outFile}\n\n` +
208
228
  `To stop the server, press Ctrl+C`);
209
229
  });
230
+ // Store server reference for shutdown route
231
+ serverRef.current = server;
210
232
  // Handle server errors
211
233
  server.on('error', (error) => {
212
234
  if (error.code === 'EADDRINUSE') {
@@ -45,7 +45,11 @@ async function run(args) {
45
45
  // Parse and validate port
46
46
  const port = (0, admin_server_utils_1.parsePort)({ portStr: flags.port });
47
47
  // Set up the Express server
48
- const { app, key, keyPath } = (0, admin_server_utils_1.setupServer)({ baseDir, outFile, bodySizeLimit });
48
+ const { app, key, keyPath, serverRef } = (0, admin_server_utils_1.setupServer)({
49
+ baseDir,
50
+ outFile,
51
+ bodySizeLimit,
52
+ });
49
53
  // Start the server and set up shutdown handlers
50
- (0, admin_server_utils_1.startServer)({ app, port, key, outFile, keyPath });
54
+ (0, admin_server_utils_1.startServer)({ app, port, key, outFile, keyPath, serverRef });
51
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/cli",
3
- "version": "3.6.3",
3
+ "version": "3.6.5",
4
4
  "description": "A command line tool for working with JBrowse 2",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "cf3dd1c895b4f3f7367093d57a0b607f54b8d7db"
51
+ "gitHead": "354d0a87b757b4d84f824b47507662f6f3a1693f"
52
52
  }