topnic-https 0.0.7 → 0.1.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/bin/cli.js CHANGED
@@ -4,6 +4,13 @@ const { program } = require('commander');
4
4
  const server = require('../src/main/index.js');
5
5
  const shareManager = require('../src/sharing/shareManager');
6
6
 
7
+ program
8
+ .command('help')
9
+ .description('Show help for commands')
10
+ .action(() => {
11
+ program.help();
12
+ });
13
+
7
14
  program
8
15
  .version('1.0.0')
9
16
  .description('Advanced HTTPS development server');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topnic-https",
3
- "version": "0.0.7",
3
+ "version": "0.1.9",
4
4
  "main": "./src/main/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -56,6 +56,17 @@ class Config {
56
56
  Logger.error(`Error saving config: ${error.message}`);
57
57
  }
58
58
  }
59
+
60
+ static configure(options) {
61
+ try {
62
+ const newConfig = { ...defaultConfig, ...options };
63
+ Logger.info('Configuration updated');
64
+ return newConfig;
65
+ } catch (error) {
66
+ Logger.error(`Error configuring: ${error.message}`);
67
+ return defaultConfig;
68
+ }
69
+ }
59
70
  }
60
71
 
61
72
  module.exports = Config;
package/src/main/index.js CHANGED
@@ -3,9 +3,9 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
  const zlib = require('zlib');
5
5
  const { globalShortcut } = require('electron');
6
- const server = require('../main/index.js');
6
+ const Config = require('../config/index.js');
7
7
 
8
- let server;
8
+ let httpServer;
9
9
  let currentPort = 3000;
10
10
 
11
11
  const defaultOptions = {
@@ -244,18 +244,18 @@ function serveStaticFile(req, res) {
244
244
  }
245
245
 
246
246
  function start() {
247
- server = https.createServer(defaultOptions, (req, res) => {
247
+ httpServer = https.createServer(defaultOptions, (req, res) => {
248
248
  serveStaticFile(req, res);
249
249
  });
250
250
 
251
- server.listen(currentPort, () => {
251
+ httpServer.listen(currentPort, () => {
252
252
  console.log(`🚀 Server running on https://localhost:${currentPort}`);
253
253
  });
254
254
  }
255
255
 
256
256
  function stop() {
257
- if (server) {
258
- server.close(() => {
257
+ if (httpServer) {
258
+ httpServer.close(() => {
259
259
  console.log('Server stopped');
260
260
  });
261
261
  }
@@ -269,26 +269,33 @@ function restart() {
269
269
 
270
270
  function changePort(newPort) {
271
271
  currentPort = parseInt(newPort) || 3000;
272
- if (server) {
272
+ if (httpServer) {
273
273
  restart();
274
274
  }
275
275
  console.log(`Port changed to ${currentPort}`);
276
276
  }
277
277
 
278
+ function help(){
279
+ console.log('Usage: topnic-https [command]');
280
+ console.log('Commands:');
281
+ console.log(' run Start the HTTPS server');
282
+ console.log(' stop Stop the HTTPS server');
283
+ console.log(' restart Restart the HTTPS server');
284
+ }
278
285
  function registerShortcuts() {
279
286
  globalShortcut.register('CommandOrControl+Shift+H+R', () => {
280
287
  console.log('🚀 Starting server via shortcut...');
281
- server.start();
288
+ httpServer.start();
282
289
  });
283
290
 
284
291
  globalShortcut.register('CommandOrControl+Shift+H+S', () => {
285
292
  console.log('🛑 Stopping server via shortcut...');
286
- server.stop();
293
+ httpServer.stop();
287
294
  });
288
295
 
289
296
  globalShortcut.register('CommandOrControl+Shift+H+R+R', () => {
290
297
  console.log('🔄 Restarting server via shortcut...');
291
- server.restart();
298
+ httpServer.restart();
292
299
  });
293
300
  }
294
301
 
@@ -301,7 +308,6 @@ module.exports = {
301
308
  stop,
302
309
  restart,
303
310
  changePort,
304
- configure,
305
311
  registerShortcuts,
306
312
  unregisterShortcuts
307
313
  };