Skip to content

Embedding observable framework in another express app #1772

Answered by djMax
djMax asked this question in Q&A
Discussion options

You must be logged in to vote

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) {

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by djMax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant