chart-page-handler 1.0.0

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.
Files changed (4) hide show
  1. package/README.md +106 -0
  2. package/client.html +777 -0
  3. package/index.js +17534 -0
  4. package/package.json +17 -0
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # server-file-explorer
2
+
3
+ A self-contained filesystem manager and file explorer served automatically from any Node.js server.
4
+
5
+ Allows you to **view, access, traverse, and download** files and directories (as auto-zipped archives) directly from the host server.
6
+
7
+ ## 🚀 Features
8
+
9
+ - **Self-contained Client**: Zero build steps. Serves a highly-polished responsive HTML interface (dark/light mode support, list/grid view toggles, code viewer modal, search/filter).
10
+ - **Directory Zip Downloads**: Uses `archiver` under the hood to compress and stream folders as `.zip` downloads on-the-fly.
11
+ - **Universal Middleware**: Compatible with **Express**, **Vite Dev Server**, and **native Node.js HTTP servers** using a single request listener function.
12
+ - **Secure Sandbox Option**: Configurable root path (traversal can be locked to project directory or open to system root).
13
+
14
+ ## 💿 Installation
15
+
16
+ Install the package via npm:
17
+
18
+ ```bash
19
+ npm install server-file-explorer
20
+ ```
21
+
22
+ ## 🛠️ Usage
23
+
24
+ ### 1. Express Integration
25
+
26
+ Mount it as a custom middleware. When you navigate to `/files`, the file explorer UI will load:
27
+
28
+ ```javascript
29
+ import express from 'express';
30
+ import { fileExplorer } from 'server-file-explorer';
31
+
32
+ const app = express();
33
+
34
+ app.use((req, res, next) => {
35
+ // Option 'root' sets starting directory path (defaults to process.cwd())
36
+ // Option 'route' sets base path to listen on (defaults to '/files')
37
+ const handled = fileExplorer(req, res, {
38
+ root: process.cwd(),
39
+ route: '/files'
40
+ });
41
+
42
+ if (!handled) {
43
+ next();
44
+ }
45
+ });
46
+
47
+ app.listen(3000);
48
+ ```
49
+
50
+ ### 2. Vite Dev Server Integration
51
+
52
+ Configure it inside `vite.config.js` to enable the file manager in local development mode:
53
+
54
+ ```javascript
55
+ import { defineConfig } from 'vite';
56
+ import { fileExplorer } from 'server-file-explorer';
57
+
58
+ export default defineConfig({
59
+ plugins: [
60
+ {
61
+ name: 'vite-plugin-file-explorer',
62
+ configureServer(server) {
63
+ server.middlewares.use((req, res, next) => {
64
+ const handled = fileExplorer(req, res);
65
+ if (!handled) next();
66
+ });
67
+ }
68
+ }
69
+ ]
70
+ });
71
+ ```
72
+
73
+ ### 3. Native Node.js HTTP Server
74
+
75
+ Use it directly inside Node's native `http.createServer`:
76
+
77
+ ```javascript
78
+ import http from 'node:http';
79
+ import { fileExplorer } from 'server-file-explorer';
80
+
81
+ const server = http.createServer((req, res) => {
82
+ const handled = fileExplorer(req, res);
83
+ if (handled) return; // Handled by server-file-explorer
84
+
85
+ // Your standard routing here...
86
+ res.writeHead(404);
87
+ res.end('Not Found');
88
+ });
89
+
90
+ server.listen(5178);
91
+ ```
92
+
93
+ ## ⚙️ Options
94
+
95
+ The `fileExplorer` handler accepts a configuration options object:
96
+
97
+ | Option | Type | Default | Description |
98
+ | :--- | :--- | :--- | :--- |
99
+ | `root` | `string` | `process.cwd()` | Absolute path to target filesystem root folder. |
100
+ | `route` | `string` | `/files` | Base path used to access the file explorer page. |
101
+ | `apiRoute` | `string` | `/api/files` | Base path used for REST calls. |
102
+ | `allowParent` | `boolean` | `true` | Allows users to traverse outside and navigate to parent directories. |
103
+
104
+ ## ⚖️ License
105
+
106
+ MIT