topnic-https 0.0.7 → 0.1.8

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": "topnic-https",
3
- "version": "0.0.7",
3
+ "version": "0.1.8",
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,7 +269,7 @@ 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}`);
@@ -278,17 +278,17 @@ function changePort(newPort) {
278
278
  function registerShortcuts() {
279
279
  globalShortcut.register('CommandOrControl+Shift+H+R', () => {
280
280
  console.log('🚀 Starting server via shortcut...');
281
- server.start();
281
+ httpServer.start();
282
282
  });
283
283
 
284
284
  globalShortcut.register('CommandOrControl+Shift+H+S', () => {
285
285
  console.log('🛑 Stopping server via shortcut...');
286
- server.stop();
286
+ httpServer.stop();
287
287
  });
288
288
 
289
289
  globalShortcut.register('CommandOrControl+Shift+H+R+R', () => {
290
290
  console.log('🔄 Restarting server via shortcut...');
291
- server.restart();
291
+ httpServer.restart();
292
292
  });
293
293
  }
294
294