-
I would like to embed observable in an existing express app. I generally have things working properly in "production" but I'm having a hard time integrating |
Beta Was this translation helpful? Give feedback.
Answered by
djMax
Oct 21, 2024
Replies: 1 comment
-
I have made something that seemingly works, by doing this: // observable.d.ts
declare module '@observablehq/framework/dist/preview.js' {
import type { IncomingMessage, Server, ServerResponse } from 'http';
declare class PreviewServer {
constructor(args: {
server: Server;
});
_handleRequest(req: IncomingMessage, res: ServerResponse): void;
}
export { PreviewServer };
} export async function attachObservablePreview(server: Server) {
const { PreviewServer } = await import('@observablehq/framework/dist/preview.js');
const observablePreview = new PreviewServer({
server: Object.create(server, {
on: {
value(event: string, listener: () => unknown) {
// Ignore request event listeners because we will handle those out of band
if (event === 'request') {
return this;
}
return server.on(event, listener);
},
},
}),
});
app.get(/.*/, observablePreview._handleRequest);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
djMax
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have made something that seemingly works, by doing this: