Skip to content

Commit 437e63a

Browse files
committed
html: embed gziped version
1 parent 0e728e6 commit 437e63a

8 files changed

Lines changed: 8541 additions & 34036 deletions

File tree

.github/workflows/backend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install packages
2121
run: |
2222
sudo apt-get update
23-
sudo apt-get install build-essential cmake libjson-c-dev libssl-dev libuv1-dev
23+
sudo apt-get install build-essential cmake libjson-c-dev zlib1g-dev libssl-dev libuv1-dev
2424
- name: Install libwebsockets-${{ matrix.lws-version }}
2525
env:
2626
LWS_VERSION: ${{ matrix.lws-version }}

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(LIBWEBSOCKETS_MIN_VERSION 1.7.0)
3333
set(SOURCE_FILES src/server.c src/http.c src/protocol.c src/terminal.c src/utils.c)
3434

3535
find_package(OpenSSL REQUIRED)
36+
find_package(ZLIB REQUIRED)
3637
find_package(Libwebsockets ${LIBWEBSOCKETS_MIN_VERSION} QUIET)
3738

3839
find_package(PkgConfig)
@@ -59,8 +60,8 @@ find_library(LIBUV_LIBRARIES NAMES uv libuv HINTS ${PC_LIBUV_LIBDIR})
5960
find_package_handle_standard_args(LIBUV DEFAULT_MSG LIBUV_LIBRARIES LIBUV_INCLUDE_DIRS)
6061
mark_as_advanced(LIBUV_INCLUDE_DIRS LIBUV_LIBRARIES)
6162

62-
set(INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS} ${JSON-C_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS})
63-
set(LINK_LIBS ${OPENSSL_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES} ${LIBUV_LIBRARIES})
63+
set(INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS} ${JSON-C_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS})
64+
set(LINK_LIBS ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES} ${LIBUV_LIBRARIES})
6465

6566
if(APPLE)
6667
# required for the new homebrew version of libwebsockets

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ brew install ttyd
3030
- Build from source (debian/ubuntu):
3131

3232
```bash
33-
sudo apt-get install cmake g++ pkg-config git vim-common libwebsockets-dev libjson-c-dev libssl-dev
33+
sudo apt-get install cmake g++ pkg-config git libwebsockets-dev libjson-c-dev zlib1g-dev libssl-dev libuv1-dev
3434
git clone https://github.com/tsl0922/ttyd.git
3535
cd ttyd && mkdir build && cd build
3636
cmake ..

html/gulpfile.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
const { src, dest, task } = require("gulp");
22
const clean = require('gulp-clean');
3+
const gzip = require('gulp-gzip');
34
const inlineSource = require('gulp-inline-source');
45
const rename = require("gulp-rename");
56
const through = require('through2');
67

7-
const toCHeader = () => {
8-
return through.obj((file, enc, cb) => {
9-
const buf = file.contents;
10-
const len = buf.length;
11-
let idx = 0;
12-
let data = "unsigned char index_html[] = {\n ";
8+
const genHeader = (size, buf, len) => {
9+
let idx = 0;
10+
let data = "unsigned char index_html[] = {\n ";
1311

14-
for (const value of buf) {
15-
idx++;
12+
for (const value of buf) {
13+
idx++;
1614

17-
let current = value < 0 ? value + 256 : value;
15+
let current = value < 0 ? value + 256 : value;
1816

19-
data += "0x";
20-
data += (current >>> 4).toString(16);
21-
data += (current & 0xF).toString(16);
17+
data += "0x";
18+
data += (current >>> 4).toString(16);
19+
data += (current & 0xF).toString(16);
2220

23-
if (idx === len) {
24-
data += "\n";
25-
} else {
26-
data += idx % 12 === 0 ? ",\n " : ", ";
27-
}
21+
if (idx === len) {
22+
data += "\n";
23+
} else {
24+
data += idx % 12 === 0 ? ",\n " : ", ";
2825
}
26+
}
2927

30-
data += "};\n";
31-
data += `unsigned int index_html_len = ${len};\n`;
32-
file.contents = Buffer.from(data);
33-
34-
return cb(null, file);
35-
});
28+
data += "};\n";
29+
data += `unsigned int index_html_len = ${len};\n`;
30+
data += `unsigned int index_html_size = ${size};\n`;
31+
return data;
3632
};
33+
let fileSize = 0;
3734

3835
task('clean', () => {
3936
return src('dist', {read: false, allowEmpty: true})
@@ -43,7 +40,16 @@ task('clean', () => {
4340
task('default', () => {
4441
return src('dist/index.html')
4542
.pipe(inlineSource())
46-
.pipe(toCHeader())
43+
.pipe(through.obj((file, enc, cb) => {
44+
fileSize = file.contents.length;
45+
return cb(null, file);
46+
}))
47+
.pipe(gzip())
48+
.pipe(through.obj((file, enc, cb) => {
49+
const buf = file.contents;
50+
file.contents = Buffer.from(genHeader(fileSize, buf, buf.length));
51+
return cb(null, file);
52+
}))
4753
.pipe(rename("html.h"))
4854
.pipe(dest('../src/'));
4955
});

html/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"gts": "^1.1.2",
3838
"gulp": "^4.0.2",
3939
"gulp-clean": "^0.4.0",
40+
"gulp-gzip": "^1.4.2",
4041
"gulp-inline-source": "^4.0.0",
4142
"gulp-rename": "^2.0.0",
4243
"html-webpack-plugin": "^3.2.0",

html/yarn.lock

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ any-observable@^0.3.0:
415415
resolved "https://registry.yarnpkg.com/any-observable/-/any-observable-0.3.0.tgz#af933475e5806a67d0d7df090dd5e8bef65d119b"
416416
integrity sha512-/FQM1EDkTsf63Ub2C6O7GuYFDsSXUwsaZDurV0np41ocwq0jthUAYCmhBX9f+KwlaCgIuWyr/4WlUQUBfKfZog==
417417

418+
any-promise@^1.1.0:
419+
version "1.3.0"
420+
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
421+
integrity sha1-q8av7tzqUugJzcA3au0845Y10X8=
422+
418423
anymatch@^2.0.0:
419424
version "2.0.0"
420425
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"
@@ -950,7 +955,7 @@ bytes@3.0.0:
950955
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
951956
integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=
952957

953-
bytes@3.1.0:
958+
bytes@3.1.0, bytes@^3.0.0:
954959
version "3.1.0"
955960
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
956961
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
@@ -3282,6 +3287,18 @@ gulp-cli@^2.2.0:
32823287
v8flags "^3.0.1"
32833288
yargs "^7.1.0"
32843289

3290+
gulp-gzip@^1.4.2:
3291+
version "1.4.2"
3292+
resolved "https://registry.yarnpkg.com/gulp-gzip/-/gulp-gzip-1.4.2.tgz#0422a94014248655b5b1a9eea1c2abee1d4f4337"
3293+
integrity sha512-ZIxfkUwk2XmZPTT9pPHrHUQlZMyp9nPhg2sfoeN27mBGpi7OaHnOD+WCN41NXjfJQ69lV1nQ9LLm1hYxx4h3UQ==
3294+
dependencies:
3295+
ansi-colors "^1.0.1"
3296+
bytes "^3.0.0"
3297+
fancy-log "^1.3.2"
3298+
plugin-error "^1.0.0"
3299+
stream-to-array "^2.3.0"
3300+
through2 "^2.0.3"
3301+
32853302
gulp-inline-source@^4.0.0:
32863303
version "4.0.0"
32873304
resolved "https://registry.yarnpkg.com/gulp-inline-source/-/gulp-inline-source-4.0.0.tgz#e0958b631719fc6a91bee29905415fa825164c69"
@@ -5881,7 +5898,7 @@ plugin-error@^0.1.2:
58815898
arr-union "^2.0.1"
58825899
extend-shallow "^1.1.2"
58835900

5884-
plugin-error@~1.0.1:
5901+
plugin-error@^1.0.0, plugin-error@~1.0.1:
58855902
version "1.0.1"
58865903
resolved "https://registry.yarnpkg.com/plugin-error/-/plugin-error-1.0.1.tgz#77016bd8919d0ac377fdcdd0322328953ca5781c"
58875904
integrity sha512-L1zP0dk7vGweZME2i+EeakvUNqSrdiI3F91TwEoYiGrAfUXmVv6fJIq4g82PAXxNsWOp0J7ZqQy/3Szz0ajTxA==
@@ -7384,6 +7401,13 @@ stream-shift@^1.0.0:
73847401
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
73857402
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=
73867403

7404+
stream-to-array@^2.3.0:
7405+
version "2.3.0"
7406+
resolved "https://registry.yarnpkg.com/stream-to-array/-/stream-to-array-2.3.0.tgz#bbf6b39f5f43ec30bc71babcb37557acecf34353"
7407+
integrity sha1-u/azn19D7DC8cbq8s3VXrOzzQ1M=
7408+
dependencies:
7409+
any-promise "^1.1.0"
7410+
73877411
strict-uri-encode@^1.0.0:
73887412
version "1.1.0"
73897413
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"

0 commit comments

Comments
 (0)