topnic-https 0.0.3 → 0.0.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.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "topnic-https",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "./src/main/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
7
7
  },
8
- "keywords": [
8
+ "keywords": [
9
9
  "https",
10
10
  "topnic",
11
11
  "manktrip",
@@ -81,15 +81,15 @@
81
81
  "https-utils"
82
82
  ],
83
83
  "author": "MankTrip",
84
- "license": "MIT",
85
- "dependencies": {
86
- "commander": "^8.3.0",
87
- "https": "^1.0.0",
88
- "fs": "^0.0.1-security",
89
- "path": "^0.12.7"
90
- },
84
+ "license": "MIT",
91
85
  "description": "مكتبة Https Topnic تسهّل إنشاء خوادم HTTPS آمنة وسريعة على localhost، مع دعم كامل للتشفير وشهادات SSL لتجربة تطوير مثالية.",
92
86
  "bin": {
93
87
  "httpst": "./bin/cli.js"
88
+ },
89
+ "dependencies": {
90
+ "commander": "^12.1.0",
91
+ "fs": "^0.0.1-security",
92
+ "https": "^1.0.0",
93
+ "path": "^0.12.7"
94
94
  }
95
95
  }
package/readme CHANGED
@@ -16,8 +16,8 @@ $ npm install -g topnic-https
16
16
  - يدعم الخادم التوجيه الأساسي
17
17
 
18
18
  # المطور
19
- - [ ] ManKTrip
19
+ - ManKTrip
20
20
 
21
21
  # الروابط
22
- - [Discord] https://discord.gg/4ye4rsXHcr
23
- - [NPM] https://www.npmjs.com/package/topnic-https
22
+ - [Discord](https://discord.gg/4ye4rsXHcr)
23
+ - [NPM](https://www.npmjs.com/package/topnic-https)
package/src/main/index.js CHANGED
@@ -10,10 +10,113 @@ const defaultOptions = {
10
10
  cert: fs.readFileSync(path.join(__dirname, '../ssl/cert.pem'))
11
11
  };
12
12
 
13
+ function serveStaticFile(req, res) {
14
+ let filePath = path.join(process.cwd(), req.url === '/' ? 'index.html' : req.url);
15
+
16
+ const extname = path.extname(filePath);
17
+
18
+ const contentTypes = {
19
+ '.html': 'text/html',
20
+ '.css': 'text/css',
21
+ '.py': 'text/x-python',
22
+ '.txt': 'text/plain',
23
+ '.c': 'text/x-csrc',
24
+ '.cpp': 'text/x-c++src',
25
+ '.cc': 'text/x-c++src',
26
+ '.h': 'text/x-chdr',
27
+ '.hpp': 'text/x-c++hdr',
28
+ '.hh': 'text/x-c++hdr',
29
+ '.js': 'text/javascript',
30
+ '.json': 'application/json',
31
+ '.png': 'image/png',
32
+ '.jpg': 'image/jpeg',
33
+ '.gif': 'image/gif',
34
+ '.svg': 'image/svg+xml',
35
+ '.ico': 'image/x-icon',
36
+ '.webp': 'image/webp',
37
+ '.avif': 'image/avif',
38
+ '.mp4': 'video/mp4',
39
+ '.webm': 'video/webm',
40
+ '.ogg': 'video/ogg',
41
+ '.mp3': 'audio/mpeg',
42
+ '.wav': 'audio/wav',
43
+ '.flac': 'audio/flac',
44
+ '.pdf': 'application/pdf',
45
+ '.doc': 'application/msword',
46
+ '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
47
+ '.xls': 'application/vnd.ms-excel',
48
+ '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
49
+ '.ppt': 'application/vnd.ms-powerpoint',
50
+ '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
51
+ '.zip': 'application/zip',
52
+ '.tar': 'application/x-tar',
53
+ '.gz': 'application/gzip',
54
+ '.bz2': 'application/x-bzip2',
55
+ '.xml': 'application/xml',
56
+ '.json': 'application/json',
57
+ '.wasm': 'application/wasm',
58
+ '.go': 'text/x-go',
59
+ '.rs': 'text/x-rustsrc',
60
+ '.env': 'text/plain',
61
+ '.lock': 'text/plain',
62
+ '.yml': 'text/yaml',
63
+ '.yaml': 'text/yaml',
64
+ '.toml': 'text/toml',
65
+ '.json5': 'application/json5',
66
+ '.jsonc': 'application/jsonc',
67
+ '.md': 'text/markdown',
68
+ '.mdx': 'text/markdown',
69
+ '.ts': 'text/typescript',
70
+ '.tsx': 'text/tsx',
71
+ '.jsx': 'text/jsx',
72
+ '.vue': 'text/x-vue',
73
+ '.svelte': 'text/x-svelte',
74
+ '.php': 'text/x-php',
75
+ '.rb': 'text/x-ruby',
76
+ '.swift': 'text/x-swift',
77
+ '.kt': 'text/kotlin',
78
+ '.kts': 'text/kotlin',
79
+ '.sql': 'text/x-sql',
80
+ '.sh': 'text/x-sh',
81
+ '.fish': 'text/x-fish',
82
+ '.zsh': 'text/x-zsh',
83
+ '.bash': 'text/x-sh',
84
+ '.elv': 'text/x-elvish',
85
+ '.lua': 'text/x-lua',
86
+ '.pl': 'text/x-perl',
87
+ '.pm': 'text/x-perl',
88
+ '.py': 'text/x-python',
89
+ '.r': 'text/x-rsrc',
90
+ '.rs': 'text/x-rustsrc',
91
+ '.ts': 'text/typescript',
92
+ '.tsx': 'text/tsx',
93
+ '.react': 'text/jsx',
94
+ '.jsx': 'text/jsx',
95
+ '.ts': 'text/typescript',
96
+ '.tsx': 'text/tsx'
97
+ };
98
+
99
+ const contentType = contentTypes[extname] || 'text/plain';
100
+
101
+ fs.readFile(filePath, (error, content) => {
102
+ if (error) {
103
+ if (error.code === 'ENOENT') {
104
+ res.writeHead(404);
105
+ res.end('File not found');
106
+ } else {
107
+ res.writeHead(500);
108
+ res.end('Server Error: ' + error.code);
109
+ }
110
+ } else {
111
+ res.writeHead(200, { 'Content-Type': contentType });
112
+ res.end(content);
113
+ }
114
+ });
115
+ }
116
+
13
117
  function start() {
14
118
  server = https.createServer(defaultOptions, (req, res) => {
15
- res.writeHead(200);
16
- res.end('Topnic HTTPS Server is running!');
119
+ serveStaticFile(req, res);
17
120
  });
18
121
 
19
122
  server.listen(currentPort, () => {