@eighty4/dank 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/http.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  type ServerResponse,
9
9
  } from 'node:http'
10
10
  import { extname, join } from 'node:path'
11
- import { isProductionBuild } from './flags.ts'
11
+ import mime from 'mime'
12
12
 
13
13
  export type FrontendFetcher = (
14
14
  url: URL,
@@ -147,8 +147,7 @@ async function exists(p: string): Promise<boolean> {
147
147
  }
148
148
 
149
149
  function streamFile(p: string, res: ServerResponse) {
150
- const mimeType = resolveMimeType(p)
151
- res.setHeader('Content-Type', mimeType)
150
+ res.setHeader('Content-Type', mime.getType(p) || 'application/octet-stream')
152
151
  const reading = createReadStream(p)
153
152
  reading.pipe(res)
154
153
  reading.on('error', err => {
@@ -158,33 +157,6 @@ function streamFile(p: string, res: ServerResponse) {
158
157
  })
159
158
  }
160
159
 
161
- function resolveMimeType(p: string): string {
162
- switch (extname(p)) {
163
- case '.html':
164
- return 'text/html'
165
- case '.js':
166
- return 'text/javascript'
167
- case '.json':
168
- return 'application/json'
169
- case '.css':
170
- return 'text/css'
171
- case '.svg':
172
- return 'image/svg+xml'
173
- case '.png':
174
- return 'image/png'
175
- case '.ttf':
176
- return 'font/ttf'
177
- case '.woff':
178
- return 'font/woff'
179
- case '.woff2':
180
- return 'font/woff2'
181
- default:
182
- console.warn('? mime type for', p)
183
- if (!isProductionBuild()) process.exit(1)
184
- return 'application/octet-stream'
185
- }
186
- }
187
-
188
160
  function convertHeadersFromFetch(from: Headers): OutgoingHttpHeaders {
189
161
  const to: OutgoingHttpHeaders = {}
190
162
  for (const name of from.keys()) {
package/lib_js/http.js CHANGED
@@ -2,7 +2,7 @@ import { createReadStream } from 'node:fs';
2
2
  import { stat } from 'node:fs/promises';
3
3
  import { createServer, } from 'node:http';
4
4
  import { extname, join } from 'node:path';
5
- import { isProductionBuild } from "./flags.js";
5
+ import mime from 'mime';
6
6
  export function createWebServer(port, frontendFetcher) {
7
7
  const serverAddress = 'http://localhost:' + port;
8
8
  return createServer((req, res) => {
@@ -107,8 +107,7 @@ async function exists(p) {
107
107
  }
108
108
  }
109
109
  function streamFile(p, res) {
110
- const mimeType = resolveMimeType(p);
111
- res.setHeader('Content-Type', mimeType);
110
+ res.setHeader('Content-Type', mime.getType(p) || 'application/octet-stream');
112
111
  const reading = createReadStream(p);
113
112
  reading.pipe(res);
114
113
  reading.on('error', err => {
@@ -117,33 +116,6 @@ function streamFile(p, res) {
117
116
  res.end();
118
117
  });
119
118
  }
120
- function resolveMimeType(p) {
121
- switch (extname(p)) {
122
- case '.html':
123
- return 'text/html';
124
- case '.js':
125
- return 'text/javascript';
126
- case '.json':
127
- return 'application/json';
128
- case '.css':
129
- return 'text/css';
130
- case '.svg':
131
- return 'image/svg+xml';
132
- case '.png':
133
- return 'image/png';
134
- case '.ttf':
135
- return 'font/ttf';
136
- case '.woff':
137
- return 'font/woff';
138
- case '.woff2':
139
- return 'font/woff2';
140
- default:
141
- console.warn('? mime type for', p);
142
- if (!isProductionBuild())
143
- process.exit(1);
144
- return 'application/octet-stream';
145
- }
146
- }
147
119
  function convertHeadersFromFetch(from) {
148
120
  const to = {};
149
121
  for (const name of from.keys()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eighty4/dank",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "description": "Multi-page development system for CDN-deployed websites",
6
6
  "keywords": [
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "esbuild": "^0.25.10",
22
+ "mime": "^4.1.0",
22
23
  "parse5": "^8.0.0"
23
24
  },
24
25
  "devDependencies": {