import { IncomingMessage , ServerResponse } from 'http' ; import type { Component } from 'react' ; import { createAsyncManager , createAsyncPipeline , PluginFromAsyncManager , createParallelWorkflow , createAsyncWaterfall , } from '@modern-js/plugin' ; import { enable } from '@modern-js/plugin/node' ; import type { ModernServerContext , BaseSSRServerContext , Metrics , Logger , } from '@modern-js/types/server' ; import type { NormalizedConfig } from '@modern-js/core' ; enable ( ) ; const gather = createParallelWorkflow < { addWebMiddleware : ( _input : any ) => void ; addAPIMiddleware : ( _input : any ) => void ; } > ( ) ; type ServerInitInput = { loggerOptions : any ; metricsOptions : any ; } ; type InitExtension = { logger : Logger ; metrics : Metrics ; } ; const create = createAsyncPipeline < ServerInitInput , InitExtension > ( ) ; export type Adapter = ( req : IncomingMessage , res : ServerResponse ) => void | Promise < void > ; export type WebServerStartInput = { pwd : string ; config : Record < string , any > ; } ; const prepareWebServer = createAsyncPipeline < WebServerStartInput , Adapter > ( ) ; export type APIServerStartInput = { pwd : string ; mode : 'function' | 'framework' ; prefix ? : string ; config ? : { middleware ? : Array < any > ; } ; } ; const prepareApiServer = createAsyncPipeline < APIServerStartInput , Adapter > ( ) ; const preDevServerInit = createParallelWorkflow < NormalizedConfig , any > ( ) ; const setupCompiler = createParallelWorkflow < { } , any [ ] > ( ) ; const postDevServerInit = createParallelWorkflow < NormalizedConfig , any > ( ) ; export type Route = { } ; const beforeRouteSet = createAsyncPipeline < Route [ ] , Route [ ] > ( ) ; const afterRouteSet = createAsyncPipeline ( ) ; const preServerInit = createParallelWorkflow < NormalizedConfig , any > ( ) ; const postServerInit = createParallelWorkflow < NormalizedConfig , any > ( ) ; const listen = createParallelWorkflow < { ip : string ; port : number ; } , any [ ] > ( ) ; const beforeServerReset = createParallelWorkflow ( ) ; const afterServerReset = createParallelWorkflow ( ) ; const extendSSRContext = createAsyncWaterfall < BaseSSRServerContext > ( ) ; const extendContext = createAsyncPipeline < ModernServerContext , ModernServerContext > ( ) ; const handleError = createParallelWorkflow < { error : Error ; } > ( ) ; export type RequestResult = { isfinish : boolean ; } ; const beforeMatch = createAsyncPipeline < { context : ModernServerContext ; } , any > ( ) ; const afterMatch = createAsyncPipeline < { context : ModernServerContext ; routeAPI : any ; } , any > ( ) ; export type SSRServerContext = { } ; const prefetch = createParallelWorkflow < { context : SSRServerContext ; } > ( ) ; export type RenderContext = { } ; const renderToString = createAsyncPipeline < { App : Component ; context : RenderContext ; } , string > ( ) ; const beforeRender = createAsyncPipeline < { context : ModernServerContext ; } , any > ( ) ; const afterRender = createAsyncPipeline < { context : ModernServerContext ; templateAPI : any ; } , any > ( ) ; const beforeSend = createAsyncPipeline < ModernServerContext , RequestResult > ( ) ; const afterSend = createParallelWorkflow < { context : ModernServerContext ; } > ( ) ; const reset = createParallelWorkflow ( ) ; export const createServerManager = ( ) => createAsyncManager ( { gather , create , prepareWebServer , prepareApiServer , preDevServerInit , setupCompiler , postDevServerInit , beforeRouteSet , afterRouteSet , preServerInit , postServerInit , listen , beforeServerReset , afterServerReset , extendSSRContext , extendContext , handleError , beforeMatch , afterMatch , prefetch , renderToString , beforeRender , afterRender , beforeSend , afterSend , reset , } ) ; export const serverManager = createServerManager ( ) ; export type ServerPlugin = PluginFromAsyncManager < typeof serverManager > ; export const { createPlugin } = serverManager ; export const collectPlugin = ( ) : Plugin [ ] => [ ] ;