Skip to content

Commit 7874434

Browse files
authored
Merge pull request #5 from bitIO/options
New command line options and docs
2 parents b1da212 + 632cd3b commit 7874434

File tree

6 files changed

+296
-26
lines changed

6 files changed

+296
-26
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# express-rest-file-server
2-
[![travis-ci](https://travis-ci.org/bitIO/express-rest-file-server.svg?branch=master)](https://travis-ci.org/bitIO/express-rest-file-server)
2+
[![Build Status](https://travis-ci.org/bitIO/express-rest-file-server.svg?branch=master)](https://travis-ci.org/bitIO/express-rest-file-server)
33
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
4+
[![Version npm](https://img.shields.io/npm/v/express-rest-file-server.svg?style=flat-square)](https://www.npmjs.com/package/express-rest-file-server)
5+
[![npm Downloads](https://img.shields.io/npm/dm/express-rest-file-server.svg?style=flat-square)](https://npmcharts.com/compare/express-rest-file-server?minimal=true)
6+
7+
[![NPM](https://nodei.co/npm/express-rest-file-server.png?downloads=true&downloadRank=true)](https://nodei.co/npm/express-rest-file-server/)
48

59
An express based application, inspired by [mock-file-server](https://github.com/betajs/mock-file-server), to be used as a CRUD file server storing content in the memory (temporal) or in the disk (permanent) of the server.
610

@@ -29,3 +33,32 @@ npx express-rest-file-server
2933
* storageType: can be `memory` or `disk` (defaults to memory)
3034
* storagePath: where to store the files if storage is set to `disk` (defaults to `/tmp`)
3135

36+
## Routes
37+
38+
### POST /files
39+
40+
Uploads a file to the store with its original name
41+
42+
### POST /files/:filename
43+
44+
Uploads a file to the store with a custom name (:filename)
45+
46+
### POST /files/chunk/:filename
47+
48+
Uploads a chuck of a file to the store with a custom name (:filename)
49+
50+
### POST /files/assemble/:filename
51+
52+
_Builds_ a file from its chunks
53+
54+
### GET /files/:filename
55+
56+
Retrieve a file by its name
57+
58+
### GET /files/:filename/size
59+
60+
Retrieve a file size by its name
61+
62+
### DELETE /files/:filename
63+
64+
Remove a file by its name

package-lock.json

Lines changed: 211 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"commit": "git-cz",
3232
"prebuild": "rimraf lib",
3333
"prepublishOnly": "pkg-ok",
34-
"start": "babel-node src/index.js",
34+
"start": "babel-node src/index.js -v",
3535
"start:disk": "babel-node src/index.js --storageType=disk",
3636
"start:prod": "node lib/index.js",
3737
"test": "echo \"Error: no test specified\" && exit 0",
@@ -48,6 +48,7 @@
4848
},
4949
"devDependencies": {
5050
"babel-cli": "^6.26.0",
51+
"babel-preset-stage-0": "^6.24.1",
5152
"commitizen": "^2.9.6",
5253
"cz-conventional-changelog": "^2.1.0",
5354
"eslint": "^4.19.1",
@@ -60,7 +61,10 @@
6061
},
6162
"babel": {
6263
"plugins": [],
63-
"presets": "env"
64+
"presets": [
65+
"env",
66+
"stage-0"
67+
]
6468
},
6569
"eslintConfig": {
6670
"extends": "airbnb-base",

src/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import nodegetopt from 'node-getopt';
2+
import logger, { setLogLevel } from './log';
23
import server from './server';
4+
import pkg from '../package.json';
35

46
const opt = nodegetopt.create([
57
['p', 'port=PORT', 'server port (default 5000)'],
68
['', 'chunknumber=CHUNKNUMBER', "chunk number parameter (default 'chunknumber')"],
79
['', 'totalsize=TOTALSIZE', "total size parameter (default 'totalsize')"],
810
['', 'storageType=TYPE', "disk or memory (default 'memory')"],
911
['', 'storagePath=PATH', "where to save files (default '/tmp')"],
12+
['', 'route=flies', "the API starting path (default '/files')"],
13+
['v', 'verbose', 'change log level to lowest'],
1014
]).bindHelp().parseSystem().options;
1115

16+
logger.info('================================');
17+
logger.info('>>> Express REST file server');
18+
logger.info(`>>> version: ${pkg.version}`);
19+
logger.info('================================');
20+
21+
if (opt.verbose) {
22+
setLogLevel('silly');
23+
logger.debug('Command line options', opt);
24+
}
25+
1226
server.run({
13-
chunkNumber: opt.chunknumber,
1427
port: (opt.port || process.env.PORT || 5000),
28+
chunkNumber: opt.chunknumber,
1529
totalSize: opt.totalsize,
1630
storage: {
17-
type: opt.storageType,
18-
path: opt.storagePath,
31+
type: (opt.storageType || 'memory'),
32+
path: (opt.storageType === 'disk' && opt.storagePath ? opt.storagePath : '/tmp'),
1933
},
34+
route: (opt.route || 'files'),
35+
verbose: (!!opt.verbose),
2036
});

0 commit comments

Comments
 (0)