Skip to content

Commit 212f498

Browse files
authored
Merge pull request #214 from jaredwray/feat-moving-to-serve-handler-for-serve-functionality
feat: moving to serve handler for serve functionality
2 parents 4a022a4 + 3123501 commit 212f498

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
"axios": "^1.7.9",
5050
"cheerio": "^1.0.0",
5151
"ecto": "^4.1.5",
52-
"express": "^4.21.2",
5352
"feed": "^4.2.2",
5453
"he": "^1.2.0",
54+
"serve-handler": "^6.1.6",
5555
"update-notifier": "^7.3.1",
5656
"writr": "^4.3.0"
5757
},
@@ -60,6 +60,7 @@
6060
"@types/he": "^1.2.3",
6161
"@types/js-yaml": "^4.0.9",
6262
"@types/node": "^22.10.7",
63+
"@types/serve-handler": "^6.1.4",
6364
"@types/update-notifier": "^6.0.8",
6465
"@vitest/coverage-v8": "^3.0.2",
6566
"rimraf": "^6.0.1",

src/docula.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type http from 'node:http';
1+
import http from 'node:http';
22
import path from 'node:path';
33
import process from 'node:process';
44
import fs from 'node:fs';
5+
import handler from 'serve-handler';
56
import updateNotifier from 'update-notifier';
6-
import express from 'express';
77
import {DoculaOptions} from './options.js';
88
import {DoculaConsole} from './console.js';
99
import {DoculaBuilder} from './builder.js';
@@ -216,20 +216,28 @@ export default class Docula {
216216
* @param {DoculaOptions} options
217217
* @returns {Promise<void>}
218218
*/
219-
public async serve(options: DoculaOptions): Promise<void> {
219+
public async serve(options: DoculaOptions): Promise<http.Server> {
220220
if (this._server) {
221221
this._server.close();
222222
}
223223

224-
const app = express();
225224
const {port} = options;
226225
const {outputPath} = options;
227226

228-
app.use(express.static(outputPath));
227+
const config = {
228+
public: outputPath,
229+
};
229230

230-
this._server = app.listen(port, () => {
231+
this._server = http.createServer(async (request, response) =>
232+
/* c8 ignore next */
233+
handler(request, response, config),
234+
);
235+
236+
this._server.listen(port, () => {
231237
this._console.log(`Docula 🦇 at http://localhost:${port}`);
232238
});
239+
240+
return this._server;
233241
}
234242
}
235243

0 commit comments

Comments
 (0)