-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcute-files.js
More file actions
executable file
·62 lines (36 loc) · 1.32 KB
/
cute-files.js
File metadata and controls
executable file
·62 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
var path = require('path');
var express = require('express');
var contentDisposition = require('content-disposition');
var pkg = require( path.join(__dirname, 'package.json') );
var scan = require('./scan');
// Parse command line options
var program = require('commander');
program
.version(pkg.version)
.option('-p, --port <port>', 'Port on which to listen to (defaults to 3000)', parseInt)
.parse(process.argv);
var port = program.port || 3000;
// Scan the directory in which the script was called. It will
// add the 'files/' prefix to all files and folders, so that
// download links point to our /files route
var tree = scan('.', 'files');
// Ceate a new express app
var app = express();
// Serve static files from the frontend folder
app.use('/', express.static(path.join(__dirname, 'frontend')));
// Serve files from the current directory under the /files route
app.use('/files', express.static(process.cwd(), {
index: false,
setHeaders: function(res, path){
// Set header to force files to download
res.setHeader('Content-Disposition', contentDisposition(path))
}
}));
// This endpoint is requested by our frontend JS
app.get('/scan', function(req,res){
res.send(tree);
});
// Everything is setup. Listen on the port.
app.listen(port);
console.log('Cute files is running on port ' + port);