laju-server 1.0.4 → 1.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/README.md +72 -22
- package/index.js +42 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,45 +1,95 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🚀 Laju Server
|
|
2
2
|
|
|
3
|
-
Instant static file server
|
|
3
|
+
> Instant, modern, and zero-configuration static file server.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/laju-server)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
**Laju Server** is a lightweight command-line tool that instantly turns any folder into a web server. It features a beautiful, modern UI for directory listings, automatic network discovery, and support for large file streaming.
|
|
9
|
+
|
|
10
|
+
Perfect for local development, sharing files over LAN, or testing static builds.
|
|
11
|
+
|
|
12
|
+
## ✨ Features
|
|
13
|
+
|
|
14
|
+
- **🎨 Modern UI**: Beautiful, responsive directory listing with a clean interface.
|
|
15
|
+
- **⚡ Zero Config**: Just run the command and your server is ready.
|
|
16
|
+
- **📁 Smart Listing**:
|
|
17
|
+
- SVG icons for different file types.
|
|
18
|
+
- Sorts folders and files automatically.
|
|
19
|
+
- One-click navigation and file downloads.
|
|
20
|
+
- **🌐 Network Ready**: Automatically displays LAN IP addresses for easy sharing.
|
|
21
|
+
- **🚀 High Performance**: Built on native Node.js APIs for optimal speed.
|
|
22
|
+
- **🔒 Secure**: Built-in protection against directory traversal attacks.
|
|
23
|
+
- **📺 Media Friendly**: Supports video/audio streaming (Range requests).
|
|
24
|
+
|
|
25
|
+
## 📦 Installation
|
|
26
|
+
|
|
27
|
+
You can run it directly using `npx` (recommended):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx laju-server [folder]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or install globally:
|
|
6
34
|
|
|
7
35
|
```bash
|
|
8
36
|
npm install -g laju-server
|
|
9
37
|
```
|
|
10
38
|
|
|
11
|
-
##
|
|
39
|
+
## 🛠 Usage
|
|
40
|
+
|
|
41
|
+
### Basic Usage
|
|
12
42
|
|
|
43
|
+
Serve the current directory:
|
|
13
44
|
```bash
|
|
14
|
-
# Serve folder saat ini
|
|
15
45
|
npx laju-server
|
|
46
|
+
```
|
|
16
47
|
|
|
17
|
-
|
|
18
|
-
|
|
48
|
+
Serve a specific folder:
|
|
49
|
+
```bash
|
|
50
|
+
npx laju-server ./my-project
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Options
|
|
19
54
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
npx laju-server
|
|
55
|
+
Serve on a specific port (default: 3000):
|
|
56
|
+
```bash
|
|
57
|
+
npx laju-server . -p 8080
|
|
58
|
+
# or
|
|
59
|
+
npx laju-server . --port 8080
|
|
23
60
|
```
|
|
24
61
|
|
|
25
|
-
##
|
|
62
|
+
## 🖥️ Preview
|
|
63
|
+
|
|
64
|
+
When you open a folder without an `index.html`, Laju Server presents a modern file explorer:
|
|
65
|
+
|
|
66
|
+
- **Folders** are shown with blue icons and navigation chevrons.
|
|
67
|
+
- **Files** have specific icons (Code, Image, Video, Archive, etc.) and direct download buttons.
|
|
68
|
+
- **Header** shows the current path clearly.
|
|
69
|
+
- **Mobile Ready**: Fully responsive design that works great on phones and tablets.
|
|
26
70
|
|
|
27
|
-
|
|
28
|
-
- 📁 Serve folder statis
|
|
29
|
-
- 🔒 Proteksi directory traversal
|
|
30
|
-
- 📄 Auto serve index.html
|
|
31
|
-
- 🎨 Auto detect MIME types
|
|
71
|
+
## 📝 Examples
|
|
32
72
|
|
|
33
|
-
|
|
73
|
+
**Sharing a game folder over LAN:**
|
|
74
|
+
```bash
|
|
75
|
+
npx laju-server /Volumes/Games
|
|
76
|
+
```
|
|
77
|
+
*Result: Your friends can browse and download games from `http://192.168.1.x:3000`*
|
|
34
78
|
|
|
79
|
+
**Testing a React build:**
|
|
35
80
|
```bash
|
|
36
|
-
# Serve folder build React
|
|
37
81
|
npx laju-server ./build
|
|
82
|
+
```
|
|
38
83
|
|
|
39
|
-
|
|
40
|
-
|
|
84
|
+
**Serving a static site on port 4000:**
|
|
85
|
+
```bash
|
|
86
|
+
npx laju-server ./public --port 4000
|
|
41
87
|
```
|
|
42
88
|
|
|
43
|
-
##
|
|
89
|
+
## 🤝 Contributing
|
|
90
|
+
|
|
91
|
+
Contributions are welcome! Feel free to submit a Pull Request.
|
|
92
|
+
|
|
93
|
+
## 📄 License
|
|
44
94
|
|
|
45
|
-
MIT
|
|
95
|
+
MIT © [Maulana Shalihin](https://github.com/maulanashalihin)
|
package/index.js
CHANGED
|
@@ -53,7 +53,8 @@ function startServer(folderPath, port = 3000) {
|
|
|
53
53
|
if (!err3 && stat3.isFile()) {
|
|
54
54
|
return serveFile(indexPath, stat3, req, res);
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const listUrl = req.url.endsWith('/') ? req.url : path.dirname(req.url);
|
|
57
|
+
return serveDirectoryListing(parentDir, listUrl, res);
|
|
57
58
|
});
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
@@ -87,6 +88,20 @@ function startServer(folderPath, port = 3000) {
|
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
const Icons = {
|
|
92
|
+
folder: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>',
|
|
93
|
+
back: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5v0a5.5 5.5 0 0 1-5.5 5.5H11"/></svg>',
|
|
94
|
+
file: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></svg>',
|
|
95
|
+
image: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',
|
|
96
|
+
video: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.777-.416L16 10"/><rect x="2" y="6" width="14" height="12" rx="2"/></svg>',
|
|
97
|
+
music: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>',
|
|
98
|
+
code: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
|
|
99
|
+
archive: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8v13H3V8"/><path d="M1 3h22v5H1z"/><path d="M10 12h4"/></svg>',
|
|
100
|
+
download: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/></svg>',
|
|
101
|
+
chevronRight: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>',
|
|
102
|
+
home: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>'
|
|
103
|
+
};
|
|
104
|
+
|
|
90
105
|
// Separate folders and files
|
|
91
106
|
const folders = [];
|
|
92
107
|
const files = [];
|
|
@@ -138,6 +153,29 @@ function startServer(folderPath, port = 3000) {
|
|
|
138
153
|
margin: 40px auto;
|
|
139
154
|
padding: 0 20px;
|
|
140
155
|
}
|
|
156
|
+
.home-btn {
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
width: 32px;
|
|
161
|
+
height: 32px;
|
|
162
|
+
border-radius: 8px;
|
|
163
|
+
background: var(--surface);
|
|
164
|
+
border: 1px solid var(--border);
|
|
165
|
+
color: var(--text-secondary);
|
|
166
|
+
transition: all 0.2s;
|
|
167
|
+
cursor: pointer;
|
|
168
|
+
text-decoration: none;
|
|
169
|
+
}
|
|
170
|
+
.home-btn:hover {
|
|
171
|
+
background: var(--hover);
|
|
172
|
+
color: var(--primary);
|
|
173
|
+
border-color: var(--primary);
|
|
174
|
+
}
|
|
175
|
+
.home-btn svg {
|
|
176
|
+
width: 18px;
|
|
177
|
+
height: 18px;
|
|
178
|
+
}
|
|
141
179
|
header {
|
|
142
180
|
margin-bottom: 24px;
|
|
143
181
|
display: flex;
|
|
@@ -269,12 +307,14 @@ function startServer(folderPath, port = 3000) {
|
|
|
269
307
|
.container { margin: 20px auto; }
|
|
270
308
|
.icon { width: 28px; height: 28px; margin-right: 12px; }
|
|
271
309
|
.icon svg { width: 16px; height: 16px; }
|
|
310
|
+
.home-btn { padding: 4px; }
|
|
272
311
|
}
|
|
273
312
|
</style>
|
|
274
313
|
</head>
|
|
275
314
|
<body>
|
|
276
315
|
<div class="container">
|
|
277
316
|
<header>
|
|
317
|
+
<a href="/" class="home-btn" title="Kembali ke Root">${Icons.home}</a>
|
|
278
318
|
<div class="badge">DIR</div>
|
|
279
319
|
<h1>${basePath}</h1>
|
|
280
320
|
</header>
|
|
@@ -285,19 +325,6 @@ function startServer(folderPath, port = 3000) {
|
|
|
285
325
|
<span>Action</span>
|
|
286
326
|
</div>`;
|
|
287
327
|
|
|
288
|
-
const Icons = {
|
|
289
|
-
folder: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>',
|
|
290
|
-
back: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5v0a5.5 5.5 0 0 1-5.5 5.5H11"/></svg>',
|
|
291
|
-
file: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></svg>',
|
|
292
|
-
image: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',
|
|
293
|
-
video: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.777-.416L16 10"/><rect x="2" y="6" width="14" height="12" rx="2"/></svg>',
|
|
294
|
-
music: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>',
|
|
295
|
-
code: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
|
|
296
|
-
archive: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8v13H3V8"/><path d="M1 3h22v5H1z"/><path d="M10 12h4"/></svg>',
|
|
297
|
-
download: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/></svg>',
|
|
298
|
-
chevronRight: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>'
|
|
299
|
-
};
|
|
300
|
-
|
|
301
328
|
// Add parent directory link if not at root
|
|
302
329
|
if (basePath !== '/') {
|
|
303
330
|
const parentPath = path.dirname(basePath.slice(0, -1)) || '/';
|
|
@@ -346,7 +373,7 @@ function startServer(folderPath, port = 3000) {
|
|
|
346
373
|
|
|
347
374
|
html += `\n </div>
|
|
348
375
|
<div style="margin-top: 20px; text-align: center; color: var(--text-secondary); font-size: 0.875rem;">
|
|
349
|
-
Laju Server
|
|
376
|
+
Laju Server v6
|
|
350
377
|
</div>
|
|
351
378
|
</div>
|
|
352
379
|
</body>
|