Skip to content

Commit

Permalink
Refresh server demos
Browse files Browse the repository at this point in the history
- microjs demo removed
- hapi.js demo does not work in latest version
  • Loading branch information
NuktukDev committed Apr 17, 2021
1 parent 1d7aff4 commit e958dbf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 109 deletions.
5 changes: 0 additions & 5 deletions demos/server/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.PHONY: init
init:
if [ ! -e sheetjs.xlsx ]; then ln -s ../../sheetjs.xlsx; fi
mkdir -p node_modules
cd node_modules; if [ ! -e xlsx ]; then ln -s ../../../ xlsx; fi; cd -

Expand All @@ -12,10 +11,6 @@ request: init ## request demo
express: init ## express demo
node express.js

.PHONY: micro
micro: init ## micro demo
micro -p 7262 micro.js

.PHONY: koa
koa: init ## koa demo
node koa.js
Expand Down
59 changes: 40 additions & 19 deletions demos/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ demo shows a few different strategies applied to different server frameworks.
NOTE: these examples merely demonstrate the core concepts and do not include
appropriate error checking or other production-level features.


### Express Setup

The following commands are required in order to test the [Express](https://github.com/expressjs/express) demo:

```bash
npm install express printj xlsx express-formidable
node express.js
```

### Koa Setup

The following commands are required in order to test the [Koa](https://github.com/koajs/koa) demo:

```bash
npm install koa printj formidable xlsx
node koa.js
```

### Hapi Setup

**Note: Hapi demo as written only works with Hapi version 16 and below.**

The following commands are required in order to test the [Hapi](https://github.com/hapijs/hapi) demo:

```bash
npm install hapi@16.x printj tiny-worker xlsx
node hapi.js
```



### Node Buffer

The `read` and `write` functions can handle `Buffer` data with `type:"buffer"`.
Expand Down Expand Up @@ -64,12 +96,12 @@ expected to handle:
Testing with cURL is straightforward:

```bash
# upload test.xls and update data
curl -X POST -F "data=@test.xls" http://localhost:7262/
# upload sheetjs.csv and update data
curl -X POST -F "data=@sheetjs.csv" http://localhost:7262/
# download data in SYLK format
curl -X GET http://localhost:7262/?t=slk
# read sheetjs.xlsx from the server directory
curl -X POST http://localhost:7262/?f=sheetjs.xlsx
# read sheetjs.csv from the server directory
curl -X POST http://localhost:7262/?f=sheetjs.csv
# write sheetjs.xlsb in the XLSB format
curl -X GET http://localhost:7262/?f=sheetjs.xlsb
```
Expand Down Expand Up @@ -108,17 +140,6 @@ The main server script is `koa.js` and the worker script is `koasub.js`. State
is maintained in the worker script.


## command-line utility with micro

The npm module ships with the `xlsx` command line tool. For global installs, the
script `bin/xlsx.njs` is added to a directory in `PATH`. For local installs, the
appropriate script or symbolic link is set up in `node_modules/.bin/`.

The `--arrays` option directs `xlsx` to generate an array of arrays that can be
parsed by the server. To generate files, the `json2csv` module exports the JS
array of arrays to a CSV, the server writes the file, and the `xlsx` command is
used to generate files of different formats.


## tiny-worker with hapi

Expand All @@ -132,12 +153,12 @@ Note: due to an issue with hapi payload parsing, the route `POST /file` is used
to handle the case of reading from file, so the cURL test is:

```bash
# upload test.xls and update data
curl -X POST -F "data=@test.xls" http://localhost:7262/
# upload sheetjs.csv and update data
curl -X POST -F "data=@sheetjs.csv" http://localhost:7262/
# download data in SYLK format
curl -X GET http://localhost:7262/?t=slk
# read sheetjs.xlsx from the server directory
curl -X POST http://localhost:7262/file?f=sheetjs.xlsx
# read sheetjs.csv from the server directory
curl -X POST http://localhost:7262/file?f=sheetjs.csv
# write sheetjs.xlsb in the XLSB format
curl -X GET http://localhost:7262/?f=sheetjs.xlsb
```
Expand Down
85 changes: 0 additions & 85 deletions demos/server/micro.js

This file was deleted.

File renamed without changes.
19 changes: 19 additions & 0 deletions demos/server/sheetjs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Text,Number,Rich,Span
This is Bold,123,This is Bold,This is Bold
This is Italic,234,This is Italic,This is Italic
This is Underline,345,This is Underline,This is Underline
This is Stricken,456,This is Stricken,This is Stricken
This is 18 px,567,This is 18 px,This is 18 px
This is superscript,678,This is superscript,This is superscript
This is subscript,789,This is subscript,This is subscript
This is red,135,This is red,This is red
This is green,246,This is green,This is green
This is Times,357,This is Times,This is Times
This is BIU,159,This is 01324576 yes,This is BIU
BG Green,255,White on Blue,Green on Black
Standard Newline,W S,"BR
New line","Pre
New line"
Height,100,px (not pt),yeah
Top Left,80,Middle Center,Bottom Right
Top Right,60,Bottom Center,Bottom Left

0 comments on commit e958dbf

Please sign in to comment.