|
1 | | - |
2 | | - |
3 | | -<h1 style='display:flex;gap:20px'> |
4 | | - file-server.js |
5 | | - <div style='flex:1'></div> |
6 | | - <input type=button value='download file' onclick='btn.download()' style='font-size:16px'> |
7 | | - <input type=button value='download complete' onclick='btn.download.complete()' style='font-size:16px'> |
8 | | -</h1> |
9 | | - |
10 | | - |
11 | | -## Description |
12 | | - |
13 | | -the file server is a nodejs script that allows interacting with the local file system |
14 | | -such as load, save, delete, create directory etc via a http request from say the browser |
15 | | - |
16 | | -the server does have https key and cert built in, however it will load them if there |
17 | | -are files in its directory named cert.pem and key.pem |
18 | | - |
19 | | -its use is fairly simple |
20 | | - |
21 | | -``` |
22 | | -
|
23 | | -node fs-server |
24 | | -
|
25 | | -``` |
26 | | - |
27 | | -This server can run locally and allow access to the local filesystem from the browser / javascript through https requests |
28 | | - |
29 | | -``` |
30 | | -
|
31 | | - var res = await fetch('https://localhost:3000/my-file.txt',{headers:{mode:'load',auth:'abc-123'}}) |
32 | | - var txt = await res.text(); |
33 | | - consolelog(txt); |
34 | | - |
35 | | -``` |
36 | | - |
37 | | -## requires |
38 | | - |
39 | | -- getmime.js |
40 | | -- keys.js |
41 | | -- |
42 | | - |
43 | | - |
44 | | - |
45 | | - |
46 | | - |
47 | | -the server can be interacted with via the client-side library |
48 | | - |
49 | | -[file-server.js](/libs/js/io/file-server/file-server.html) |
50 | | - |
51 | | - |
52 | | -<!-- |
53 | | -[file-server.js [ github.com ]](https://github.com/javascript-2020/libs/blob/main/js/io/file-server/file-server.js) |
54 | | ---> |
55 | | - |
56 | | - |
57 | | - |
58 | | -``` |
59 | | -
|
60 | | -
|
61 | | -<script src='https://cdn.jsdelivr.net/gh/javascript-2020/libs/js/io/file-server/file-server.js'></script> |
62 | | -
|
63 | | -<script> |
64 | | -
|
65 | | -(async()=>{ |
66 | | - |
67 | | - var fs = window['file-server']; |
68 | | - fs.url = 'https://localhost:3000'; |
69 | | - fs.auth = 'password'; |
70 | | - |
71 | | - var {blob,error} = await fs.file.load('/tmp/a.txt'); |
72 | | - if(error){ |
73 | | - console.error(error); |
74 | | - return; |
75 | | - } |
76 | | - |
77 | | - var txt = await blob.text(); |
78 | | - console.log(txt); |
79 | | - |
80 | | -})(); |
81 | | -
|
82 | | -</script> |
83 | | -
|
84 | | -``` |
85 | | - |
86 | | - |
| 1 | + |
| 2 | + |
| 3 | +<h1 style='display:flex;gap:20px'> |
| 4 | + file-server.js |
| 5 | + <div style='flex:1'></div> |
| 6 | + <input type=button value='download file' onclick='btn.download()' style='font-size:16px'> |
| 7 | + <input type=button value='download complete' onclick='btn.download.complete()' style='font-size:16px'> |
| 8 | +</h1> |
| 9 | + |
| 10 | + |
| 11 | +## Description |
| 12 | + |
| 13 | +the file server is a nodejs script that allows interacting with the local file system |
| 14 | +such as load, save, delete, create directory etc via a http request from say the browser |
| 15 | + |
| 16 | +the server does have https key and cert built in, however it will load them if there |
| 17 | +are files in its directory named cert.pem and key.pem |
| 18 | + |
| 19 | +its use is fairly simple |
| 20 | + |
| 21 | +``` |
| 22 | +
|
| 23 | +node fs-server |
| 24 | +
|
| 25 | +``` |
| 26 | + |
| 27 | +This server can run locally and allow access to the local filesystem from the browser / javascript through https requests |
| 28 | + |
| 29 | +``` |
| 30 | +
|
| 31 | + var res = await fetch('https://localhost:3000/my-file.txt',{headers:{mode:'load',auth:'abc-123'}}) |
| 32 | + var txt = await res.text(); |
| 33 | + consolelog(txt); |
| 34 | + |
| 35 | +``` |
| 36 | + |
| 37 | +## requires |
| 38 | + |
| 39 | +- getmime.js |
| 40 | +- keys.js |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +the server can be interacted with via the client-side library |
| 47 | + |
| 48 | +[file-server.js](/libs/js/io/file-server/file-server.html) |
| 49 | + |
| 50 | + |
| 51 | +<!-- |
| 52 | +[file-server.js [ github.com ]](https://github.com/javascript-2020/libs/blob/main/js/io/file-server/file-server.js) |
| 53 | +--> |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +``` |
| 58 | +
|
| 59 | +
|
| 60 | +<script src='https://cdn.jsdelivr.net/gh/javascript-2020/libs/js/io/file-server/file-server.js'></script> |
| 61 | +
|
| 62 | +<script> |
| 63 | +
|
| 64 | +(async()=>{ |
| 65 | + |
| 66 | + var fs = window['file-server']; |
| 67 | + fs.url = 'https://localhost:3000'; |
| 68 | + fs.auth = 'password'; |
| 69 | + |
| 70 | + var {blob,error} = await fs.file.load('/tmp/a.txt'); |
| 71 | + if(error){ |
| 72 | + console.error(error); |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + var txt = await blob.text(); |
| 77 | + console.log(txt); |
| 78 | + |
| 79 | +})(); |
| 80 | +
|
| 81 | +</script> |
| 82 | +
|
| 83 | +``` |
| 84 | + |
0 commit comments