|
1 |
| -import type http from 'node:http'; |
| 1 | +import http from 'node:http'; |
2 | 2 | import path from 'node:path';
|
3 | 3 | import process from 'node:process';
|
4 | 4 | import fs from 'node:fs';
|
| 5 | +import handler from 'serve-handler'; |
5 | 6 | import updateNotifier from 'update-notifier';
|
6 |
| -import express from 'express'; |
7 | 7 | import {DoculaOptions} from './options.js';
|
8 | 8 | import {DoculaConsole} from './console.js';
|
9 | 9 | import {DoculaBuilder} from './builder.js';
|
@@ -216,20 +216,28 @@ export default class Docula {
|
216 | 216 | * @param {DoculaOptions} options
|
217 | 217 | * @returns {Promise<void>}
|
218 | 218 | */
|
219 |
| - public async serve(options: DoculaOptions): Promise<void> { |
| 219 | + public async serve(options: DoculaOptions): Promise<http.Server> { |
220 | 220 | if (this._server) {
|
221 | 221 | this._server.close();
|
222 | 222 | }
|
223 | 223 |
|
224 |
| - const app = express(); |
225 | 224 | const {port} = options;
|
226 | 225 | const {outputPath} = options;
|
227 | 226 |
|
228 |
| - app.use(express.static(outputPath)); |
| 227 | + const config = { |
| 228 | + public: outputPath, |
| 229 | + }; |
229 | 230 |
|
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, () => { |
231 | 237 | this._console.log(`Docula 🦇 at http://localhost:${port}`);
|
232 | 238 | });
|
| 239 | + |
| 240 | + return this._server; |
233 | 241 | }
|
234 | 242 | }
|
235 | 243 |
|
|
0 commit comments