Skip to content

Commit

Permalink
fix: mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Aug 2, 2024
1 parent 8e8e963 commit ce58e7c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
4 changes: 3 additions & 1 deletion desktop/electron-serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import type {BrowserWindow, Protocol} from 'electron';
import {app, protocol, session} from 'electron';
import fs from 'fs';
import mime from 'mime-types';
import path from 'path';

type RegisterBufferProtocol = Protocol['registerBufferProtocol'];
Expand Down Expand Up @@ -63,11 +64,12 @@ export default function electronServe(options: ServeOptions) {
const handler: HandlerType = async (request, callback) => {
const filePath = path.join(mandatoryOptions.directory, decodeURIComponent(new URL(request.url).pathname));
const resolvedPath = (await getPath(filePath)) ?? path.join(mandatoryOptions.directory, `${mandatoryOptions.file}.html`);
const mimeType = (mime.lookup(resolvedPath) || 'application/octet-stream') as string;

try {
const data = await fs.promises.readFile(resolvedPath);
callback({
mimeType: 'text/html',
mimeType,
data: Buffer.from(data),
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
47 changes: 41 additions & 6 deletions desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
"electron-context-menu": "^2.3.0",
"electron-log": "^4.4.8",
"electron-updater": "^6.3.2",
"mime-types": "^2.1.35",
"node-machine-id": "^1.1.12"
},
"author": "Expensify, Inc.",
"license": "MIT",
"private": true
"private": true,
"devDependencies": {
"@types/mime-types": "^2.1.4"
}
}

0 comments on commit ce58e7c

Please sign in to comment.