Skip to content

Commit

Permalink
`chore(transport-bridge): simplify ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Mar 6, 2025
1 parent 3736dec commit cae3d7c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 34 deletions.
1 change: 1 addition & 0 deletions packages/transport-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"@types/json-stable-stringify": "^1",
"esbuild": "^0.23.1",
"html-inline-script-webpack-plugin": "^3.2.1",
"html-webpack-plugin": "^5.6.0",
"pkg": "^5.8.1",
"webpack": "^5.97.1"
Expand Down
32 changes: 0 additions & 32 deletions packages/transport-bridge/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,38 +441,6 @@ export class TrezordNode {
},
]);

app.get('/ui', [
(req, res) => {
const parsedUrl = new URL(req.url, `http://${req.headers.host}/`);

const pathname = path.join(__dirname, this.assetPrefix, parsedUrl.pathname);

const map: Record<string, string> = {
'.ico': 'image/x-icon',
'.html': 'text/html',
'.js': 'text/javascript',
'.json': 'application/json',
'.css': 'text/css',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.svg': 'image/svg+xml',
};

const { ext } = path.parse(pathname);
fs.stat(pathname)
.then(() => fs.readFile(pathname))
.then(data => {
res.setHeader('Content-type', map[ext] || 'text/plain');
res.end(data);
})
.catch(err => {
this.logger.error('Failed to fetch UI', err);
res.statusCode = 404;
res.end(`File ${pathname} not found!`);
});
},
]);

app.get('/logs', [
(_req, res) => {
res.writeHead(200, {
Expand Down
4 changes: 2 additions & 2 deletions packages/transport-bridge/webpack/ui.webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import HtmlInlineScriptPlugin from 'html-inline-script-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import webpack from 'webpack';
Expand Down Expand Up @@ -62,10 +63,9 @@ const config: webpack.Configuration = {
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../src/ui/index.html'),
filename: 'index.html',
inject: 'body',
publicPath: 'http://127.0.0.1:21325/ui',
}),
new HtmlInlineScriptPlugin(),
],
};

Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12753,6 +12753,7 @@ __metadata:
"@trezor/utils": "workspace:*"
"@types/json-stable-stringify": "npm:^1"
esbuild: "npm:^0.23.1"
html-inline-script-webpack-plugin: "npm:^3.2.1"
html-webpack-plugin: "npm:^5.6.0"
json-stable-stringify: "npm:^1.2.1"
pkg: "npm:^5.8.1"
Expand Down Expand Up @@ -25999,6 +26000,16 @@ __metadata:
languageName: node
linkType: hard

"html-inline-script-webpack-plugin@npm:^3.2.1":
version: 3.2.1
resolution: "html-inline-script-webpack-plugin@npm:3.2.1"
peerDependencies:
html-webpack-plugin: ^5.0.0
webpack: ^5.0.0
checksum: 10/f7a67038ee89d6447a0389e92e565fcbe5482091d688096542304ee3d3a163aa3f2d7a725ee5a3eeda707913849cc0dbb2b6489d4fc190951a178492785ebbb5
languageName: node
linkType: hard

"html-minifier-terser@npm:^6.0.2":
version: 6.1.0
resolution: "html-minifier-terser@npm:6.1.0"
Expand Down

0 comments on commit cae3d7c

Please sign in to comment.