topnic-https 0.0.4 → 0.0.6
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 +1 -1
- package/package.json +2 -1
- package/readme +9 -3
- package/src/main/index.js +259 -3
package/bin/cli.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "topnic-https",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"main": "./src/main/index.js",
|
5
5
|
"scripts": {
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
@@ -87,6 +87,7 @@
|
|
87
87
|
"httpst": "./bin/cli.js"
|
88
88
|
},
|
89
89
|
"dependencies": {
|
90
|
+
"chokidar": "^4.0.1",
|
90
91
|
"commander": "^12.1.0",
|
91
92
|
"fs": "^0.0.1-security",
|
92
93
|
"https": "^1.0.0",
|
package/readme
CHANGED
@@ -14,10 +14,16 @@ $ npm install -g topnic-https
|
|
14
14
|
- يدعم الخادم التوجيه HTTP و HTTPS
|
15
15
|
- يدعم الخادم المنطق البسيط
|
16
16
|
- يدعم الخادم التوجيه الأساسي
|
17
|
+
- يدعم الخادم الإختصارات المخصصة
|
18
|
+
|
19
|
+
## الإختصارات
|
20
|
+
- CommandOrControl+Shift+H+R - لتشغيل الخادم
|
21
|
+
- CommandOrControl+Shift+H+S - لإيقاف الخادم
|
22
|
+
- CommandOrControl+Shift+H+R+R - لإعادة تشغيل الخادم
|
17
23
|
|
18
24
|
# المطور
|
19
|
-
-
|
25
|
+
- ManKTrip
|
20
26
|
|
21
27
|
# الروابط
|
22
|
-
- [Discord]
|
23
|
-
- [NPM]
|
28
|
+
- [Discord](https://discord.gg/4ye4rsXHcr)
|
29
|
+
- [NPM](https://www.npmjs.com/package/topnic-https)
|
package/src/main/index.js
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
const https = require('https');
|
2
2
|
const fs = require('fs');
|
3
3
|
const path = require('path');
|
4
|
+
const zlib = require('zlib');
|
5
|
+
const { globalShortcut } = require('electron');
|
6
|
+
const server = require('../main/index.js');
|
4
7
|
|
5
8
|
let server;
|
6
9
|
let currentPort = 3000;
|
@@ -10,10 +13,239 @@ const defaultOptions = {
|
|
10
13
|
cert: fs.readFileSync(path.join(__dirname, '../ssl/cert.pem'))
|
11
14
|
};
|
12
15
|
|
16
|
+
const defaultCorsHeaders = {
|
17
|
+
'Access-Control-Allow-Origin': '*',
|
18
|
+
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
19
|
+
'Access-Control-Allow-Headers': 'Content-Type'
|
20
|
+
};
|
21
|
+
|
22
|
+
function serveStaticFile(req, res) {
|
23
|
+
Object.entries(defaultCorsHeaders).forEach(([key, value]) => {
|
24
|
+
res.setHeader(key, value);
|
25
|
+
});
|
26
|
+
|
27
|
+
let filePath = path.join(process.cwd(), req.url === '/' ? 'index.html' : req.url);
|
28
|
+
|
29
|
+
const extname = path.extname(filePath);
|
30
|
+
const contentTypes = {
|
31
|
+
'.html': 'text/html',
|
32
|
+
'.css': 'text/css',
|
33
|
+
'.txt': 'text/plain',
|
34
|
+
'.json': 'application/json',
|
35
|
+
'.json5': 'application/json5',
|
36
|
+
'.jsonc': 'application/jsonc',
|
37
|
+
'.py': 'text/x-python',
|
38
|
+
'.c': 'text/x-csrc',
|
39
|
+
'.cpp': 'text/x-c++src',
|
40
|
+
'.cc': 'text/x-c++src',
|
41
|
+
'.h': 'text/x-chdr',
|
42
|
+
'.hpp': 'text/x-c++hdr',
|
43
|
+
'.hh': 'text/x-c++hdr',
|
44
|
+
'.js': 'text/javascript',
|
45
|
+
'.jsx': 'text/jsx',
|
46
|
+
'.ts': 'text/typescript',
|
47
|
+
'.tsx': 'text/tsx',
|
48
|
+
'.go': 'text/x-go',
|
49
|
+
'.rs': 'text/x-rustsrc',
|
50
|
+
'.env': 'text/plain',
|
51
|
+
'.lock': 'text/plain',
|
52
|
+
'.yml': 'text/yaml',
|
53
|
+
'.yaml': 'text/yaml',
|
54
|
+
'.toml': 'text/toml',
|
55
|
+
'.md': 'text/markdown',
|
56
|
+
'.mdx': 'text/markdown',
|
57
|
+
'.vue': 'text/x-vue',
|
58
|
+
'.svelte': 'text/x-svelte',
|
59
|
+
'.php': 'text/x-php',
|
60
|
+
'.rb': 'text/x-ruby',
|
61
|
+
'.swift': 'text/x-swift',
|
62
|
+
'.kt': 'text/kotlin',
|
63
|
+
'.kts': 'text/kotlin',
|
64
|
+
'.sql': 'text/x-sql',
|
65
|
+
'.sh': 'text/x-sh',
|
66
|
+
'.fish': 'text/x-fish',
|
67
|
+
'.zsh': 'text/x-zsh',
|
68
|
+
'.bash': 'text/x-sh',
|
69
|
+
'.elv': 'text/x-elvish',
|
70
|
+
'.lua': 'text/x-lua',
|
71
|
+
'.pl': 'text/x-perl',
|
72
|
+
'.pm': 'text/x-perl',
|
73
|
+
'.r': 'text/x-rsrc',
|
74
|
+
'.xml': 'application/xml',
|
75
|
+
'.wasm': 'application/wasm',
|
76
|
+
'.png': 'image/png',
|
77
|
+
'.jpg': 'image/jpeg',
|
78
|
+
'.jpeg': 'image/jpeg',
|
79
|
+
'.gif': 'image/gif',
|
80
|
+
'.svg': 'image/svg+xml',
|
81
|
+
'.ico': 'image/x-icon',
|
82
|
+
'.webp': 'image/webp',
|
83
|
+
'.avif': 'image/avif',
|
84
|
+
'.mp4': 'video/mp4',
|
85
|
+
'.webm': 'video/webm',
|
86
|
+
'.ogg': 'video/ogg',
|
87
|
+
'.mp3': 'audio/mpeg',
|
88
|
+
'.wav': 'audio/wav',
|
89
|
+
'.flac': 'audio/flac',
|
90
|
+
'.pdf': 'application/pdf',
|
91
|
+
'.doc': 'application/msword',
|
92
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
93
|
+
'.xls': 'application/vnd.ms-excel',
|
94
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
95
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
96
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
97
|
+
'.zip': 'application/zip',
|
98
|
+
'.tar': 'application/x-tar',
|
99
|
+
'.gz': 'application/gzip',
|
100
|
+
'.bz2': 'application/x-bzip2',
|
101
|
+
'.7z': 'application/x-7z-compressed',
|
102
|
+
'.rar': 'application/x-rar-compressed',
|
103
|
+
'.xz': 'application/x-xz',
|
104
|
+
'.deb': 'application/x-debian-package',
|
105
|
+
'.iso': 'application/x-iso9660-image',
|
106
|
+
'.bin': 'application/octet-stream',
|
107
|
+
'.exe': 'application/x-msdownload',
|
108
|
+
'.msi': 'application/x-msi',
|
109
|
+
'.apk': 'application/vnd.android.package-archive',
|
110
|
+
'.dmg': 'application/x-apple-diskimage',
|
111
|
+
'.svgz': 'image/svg+xml',
|
112
|
+
'.tif': 'image/tiff',
|
113
|
+
'.tiff': 'image/tiff',
|
114
|
+
'.eps': 'application/postscript',
|
115
|
+
'.ps': 'application/postscript',
|
116
|
+
'.otf': 'font/otf',
|
117
|
+
'.ttf': 'font/ttf',
|
118
|
+
'.woff': 'font/woff',
|
119
|
+
'.woff2': 'font/woff2',
|
120
|
+
'.eot': 'application/vnd.ms-fontobject',
|
121
|
+
'.jsonld': 'application/ld+json',
|
122
|
+
'.crt': 'application/x-x509-ca-cert',
|
123
|
+
'.cer': 'application/pkix-cert',
|
124
|
+
'.pem': 'application/x-pem-file',
|
125
|
+
'.pfx': 'application/x-pkcs12',
|
126
|
+
'.key': 'application/x-pem-file',
|
127
|
+
'.ics': 'text/calendar',
|
128
|
+
'.csv': 'text/csv',
|
129
|
+
'.tsv': 'text/tab-separated-values',
|
130
|
+
'.webmanifest': 'application/manifest+json',
|
131
|
+
'.mpg': 'video/mpeg',
|
132
|
+
'.mpeg': 'video/mpeg',
|
133
|
+
'.mov': 'video/quicktime',
|
134
|
+
'.avi': 'video/x-msvideo',
|
135
|
+
'.mkv': 'video/x-matroska',
|
136
|
+
'.bat': 'application/x-bat',
|
137
|
+
'.ini': 'text/plain',
|
138
|
+
'.log': 'text/plain',
|
139
|
+
'.xsl': 'application/xml',
|
140
|
+
'.xsd': 'application/xml',
|
141
|
+
'.xhtml': 'application/xhtml+xml',
|
142
|
+
'.rss': 'application/rss+xml',
|
143
|
+
'.atom': 'application/atom+xml',
|
144
|
+
'.m3u8': 'application/x-mpegURL',
|
145
|
+
'.ts': 'video/mp2t',
|
146
|
+
'.jsonl': 'application/jsonl',
|
147
|
+
'.ndjson': 'application/x-ndjson',
|
148
|
+
'.geojson': 'application/geo+json',
|
149
|
+
'.3gp': 'video/3gpp',
|
150
|
+
'.3g2': 'video/3gpp2',
|
151
|
+
'.jar': 'application/java-archive',
|
152
|
+
'.war': 'application/java-archive',
|
153
|
+
'.ear': 'application/java-archive',
|
154
|
+
'.csv.gz': 'application/gzip',
|
155
|
+
'.stl': 'model/stl',
|
156
|
+
'.step': 'application/step',
|
157
|
+
'.iges': 'application/iges',
|
158
|
+
'.glb': 'model/gltf-binary',
|
159
|
+
'.gltf': 'model/gltf+json',
|
160
|
+
'.obj': 'model/obj',
|
161
|
+
'.fbx': 'model/fbx',
|
162
|
+
'.vrml': 'model/vrml',
|
163
|
+
'.dae': 'model/vnd.collada+xml',
|
164
|
+
'.3dm': 'model/x-3dmf',
|
165
|
+
'.blend': 'application/x-blender',
|
166
|
+
'.bak': 'application/octet-stream',
|
167
|
+
'.sql.gz': 'application/gzip',
|
168
|
+
'.ttc': 'font/collection',
|
169
|
+
'.cab': 'application/vnd.ms-cab-compressed',
|
170
|
+
'.lz': 'application/x-lzip',
|
171
|
+
'.lzma': 'application/x-lzma',
|
172
|
+
'.z': 'application/x-compress',
|
173
|
+
'.rpm': 'application/x-rpm',
|
174
|
+
'.cpio': 'application/x-cpio',
|
175
|
+
'.xz': 'application/x-xz',
|
176
|
+
'.img': 'application/octet-stream',
|
177
|
+
'.fits': 'application/fits',
|
178
|
+
'.parquet': 'application/octet-stream',
|
179
|
+
'.orc': 'application/octet-stream',
|
180
|
+
'.avro': 'application/octet-stream',
|
181
|
+
'.yaml.gz': 'application/gzip',
|
182
|
+
'.sql.lz': 'application/x-lzip',
|
183
|
+
'.sql.xz': 'application/x-xz',
|
184
|
+
'.json.gz': 'application/gzip',
|
185
|
+
'.json.xz': 'application/x-xz',
|
186
|
+
'.json5.gz': 'application/gzip',
|
187
|
+
'.json5.xz': 'application/x-xz',
|
188
|
+
'.jsonc.gz': 'application/gzip',
|
189
|
+
'.jsonc.xz': 'application/x-xz',
|
190
|
+
'.jsonl.gz': 'application/gzip',
|
191
|
+
'.jsonl.xz': 'application/x-xz',
|
192
|
+
'.ndjson.gz': 'application/gzip',
|
193
|
+
'.ndjson.xz': 'application/x-xz',
|
194
|
+
'.parquet.gz': 'application/gzip',
|
195
|
+
'.parquet.xz': 'application/x-xz',
|
196
|
+
'.orc.gz': 'application/gzip',
|
197
|
+
'.orc.xz': 'application/x-xz',
|
198
|
+
'.avro.gz': 'application/gzip',
|
199
|
+
'.avro.xz': 'application/x-xz'
|
200
|
+
};
|
201
|
+
|
202
|
+
const contentType = contentTypes[extname] || 'text/plain';
|
203
|
+
|
204
|
+
fs.readFile(filePath, (error, content) => {
|
205
|
+
if (error) {
|
206
|
+
if (error.code === 'ENOENT') {
|
207
|
+
res.writeHead(404);
|
208
|
+
res.end('File not found');
|
209
|
+
} else {
|
210
|
+
res.writeHead(500);
|
211
|
+
res.end('Server Error: ' + error.code);
|
212
|
+
}
|
213
|
+
} else {
|
214
|
+
const acceptEncoding = req.headers['accept-encoding'] || '';
|
215
|
+
|
216
|
+
if (acceptEncoding.includes('gzip')) {
|
217
|
+
res.writeHead(200, {
|
218
|
+
'Content-Type': contentType,
|
219
|
+
'Content-Encoding': 'gzip'
|
220
|
+
});
|
221
|
+
zlib.gzip(content, (_, result) => res.end(result));
|
222
|
+
} else if (acceptEncoding.includes('deflate')) {
|
223
|
+
res.writeHead(200, {
|
224
|
+
'Content-Type': contentType,
|
225
|
+
'Content-Encoding': 'deflate'
|
226
|
+
});
|
227
|
+
zlib.deflate(content, (_, result) => res.end(result));
|
228
|
+
} else {
|
229
|
+
res.writeHead(200, { 'Content-Type': contentType });
|
230
|
+
res.end(content);
|
231
|
+
}
|
232
|
+
}
|
233
|
+
});
|
234
|
+
|
235
|
+
const cacheControl = {
|
236
|
+
'.html': 'no-cache',
|
237
|
+
'.css': 'public, max-age=31536000',
|
238
|
+
'.js': 'public, max-age=31536000',
|
239
|
+
'.png': 'public, max-age=31536000',
|
240
|
+
'.jpg': 'public, max-age=31536000'
|
241
|
+
};
|
242
|
+
|
243
|
+
res.setHeader('Cache-Control', cacheControl[extname] || 'no-cache');
|
244
|
+
}
|
245
|
+
|
13
246
|
function start() {
|
14
247
|
server = https.createServer(defaultOptions, (req, res) => {
|
15
|
-
res
|
16
|
-
res.end('Topnic HTTPS Server is running!');
|
248
|
+
serveStaticFile(req, res);
|
17
249
|
});
|
18
250
|
|
19
251
|
server.listen(currentPort, () => {
|
@@ -43,9 +275,33 @@ function changePort(newPort) {
|
|
43
275
|
console.log(`Port changed to ${currentPort}`);
|
44
276
|
}
|
45
277
|
|
278
|
+
function registerShortcuts() {
|
279
|
+
globalShortcut.register('CommandOrControl+Shift+H+R', () => {
|
280
|
+
console.log('🚀 Starting server via shortcut...');
|
281
|
+
server.start();
|
282
|
+
});
|
283
|
+
|
284
|
+
globalShortcut.register('CommandOrControl+Shift+H+S', () => {
|
285
|
+
console.log('🛑 Stopping server via shortcut...');
|
286
|
+
server.stop();
|
287
|
+
});
|
288
|
+
|
289
|
+
globalShortcut.register('CommandOrControl+Shift+H+R+R', () => {
|
290
|
+
console.log('🔄 Restarting server via shortcut...');
|
291
|
+
server.restart();
|
292
|
+
});
|
293
|
+
}
|
294
|
+
|
295
|
+
function unregisterShortcuts() {
|
296
|
+
globalShortcut.unregisterAll();
|
297
|
+
}
|
298
|
+
|
46
299
|
module.exports = {
|
47
300
|
start,
|
48
301
|
stop,
|
49
302
|
restart,
|
50
|
-
changePort
|
303
|
+
changePort,
|
304
|
+
configure,
|
305
|
+
registerShortcuts,
|
306
|
+
unregisterShortcuts
|
51
307
|
};
|