vite-plugin-files-server 1.0.0 → 1.0.2
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/dist/index.cjs +16 -8
- package/dist/index.js +16 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -368,6 +368,9 @@ function fileServerPlugin(options = {}) {
|
|
|
368
368
|
if (!enable) return;
|
|
369
369
|
server.middlewares.use((req, res, next) => {
|
|
370
370
|
const url = req.url ? decodeURIComponent(req.url.split("?")[0]) : "/";
|
|
371
|
+
if (url.startsWith("/@") || url.includes("vite")) {
|
|
372
|
+
return next();
|
|
373
|
+
}
|
|
371
374
|
const projectRoot = server.config.root;
|
|
372
375
|
const fullPath = import_path.default.join(projectRoot, url);
|
|
373
376
|
try {
|
|
@@ -387,24 +390,29 @@ function fileServerPlugin(options = {}) {
|
|
|
387
390
|
const isDir = import_fs.default.statSync(filePath).isDirectory();
|
|
388
391
|
const href = import_path.default.join(url, file).replace(/\\/g, "/");
|
|
389
392
|
const item = `
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
<li>
|
|
394
|
+
<a href="${href}" class="icon ${isDir ? "icon-directory" : "icon-html icon-text-html"}">
|
|
395
|
+
<span class="name">${file}</span>
|
|
396
|
+
</a>
|
|
397
|
+
</li>`;
|
|
395
398
|
return item;
|
|
396
399
|
}).join("");
|
|
397
400
|
urlSplitArray = urlSplitArray.slice(0, -1);
|
|
398
401
|
let backUrl = urlSplitArray.join("/");
|
|
399
402
|
const backItem = `
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
+
<li>
|
|
404
|
+
<a href="${backUrl}" class="icon icon-directory"><span class="name">..</span></a>
|
|
405
|
+
</li>`;
|
|
403
406
|
let fullList = urlSplitArray.length > 1 ? backItem + listItems : listItems;
|
|
404
407
|
const html = temp_default.replace(/{{title}}/g, `Index of ${url}`).replace(/{{headItem}}/g, headItem).replace(/{{url}}/g, url).replace(/{{listItems}}/g, fullList);
|
|
405
408
|
res.setHeader("Content-Type", "text/html");
|
|
406
409
|
res.end(html);
|
|
407
410
|
return;
|
|
411
|
+
} else if (!import_fs.default.existsSync(fullPath)) {
|
|
412
|
+
const html = "path not found";
|
|
413
|
+
res.setHeader("Content-Type", "text/html");
|
|
414
|
+
res.end(html);
|
|
415
|
+
return;
|
|
408
416
|
}
|
|
409
417
|
} catch (e) {
|
|
410
418
|
console.error("File Server Plugin Error:", e);
|
package/dist/index.js
CHANGED
|
@@ -334,6 +334,9 @@ function fileServerPlugin(options = {}) {
|
|
|
334
334
|
if (!enable) return;
|
|
335
335
|
server.middlewares.use((req, res, next) => {
|
|
336
336
|
const url = req.url ? decodeURIComponent(req.url.split("?")[0]) : "/";
|
|
337
|
+
if (url.startsWith("/@") || url.includes("vite")) {
|
|
338
|
+
return next();
|
|
339
|
+
}
|
|
337
340
|
const projectRoot = server.config.root;
|
|
338
341
|
const fullPath = path.join(projectRoot, url);
|
|
339
342
|
try {
|
|
@@ -353,24 +356,29 @@ function fileServerPlugin(options = {}) {
|
|
|
353
356
|
const isDir = fs.statSync(filePath).isDirectory();
|
|
354
357
|
const href = path.join(url, file).replace(/\\/g, "/");
|
|
355
358
|
const item = `
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
<li>
|
|
360
|
+
<a href="${href}" class="icon ${isDir ? "icon-directory" : "icon-html icon-text-html"}">
|
|
361
|
+
<span class="name">${file}</span>
|
|
362
|
+
</a>
|
|
363
|
+
</li>`;
|
|
361
364
|
return item;
|
|
362
365
|
}).join("");
|
|
363
366
|
urlSplitArray = urlSplitArray.slice(0, -1);
|
|
364
367
|
let backUrl = urlSplitArray.join("/");
|
|
365
368
|
const backItem = `
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
<li>
|
|
370
|
+
<a href="${backUrl}" class="icon icon-directory"><span class="name">..</span></a>
|
|
371
|
+
</li>`;
|
|
369
372
|
let fullList = urlSplitArray.length > 1 ? backItem + listItems : listItems;
|
|
370
373
|
const html = temp_default.replace(/{{title}}/g, `Index of ${url}`).replace(/{{headItem}}/g, headItem).replace(/{{url}}/g, url).replace(/{{listItems}}/g, fullList);
|
|
371
374
|
res.setHeader("Content-Type", "text/html");
|
|
372
375
|
res.end(html);
|
|
373
376
|
return;
|
|
377
|
+
} else if (!fs.existsSync(fullPath)) {
|
|
378
|
+
const html = "path not found";
|
|
379
|
+
res.setHeader("Content-Type", "text/html");
|
|
380
|
+
res.end(html);
|
|
381
|
+
return;
|
|
374
382
|
}
|
|
375
383
|
} catch (e) {
|
|
376
384
|
console.error("File Server Plugin Error:", e);
|