@@ -58,54 +58,13 @@ export default class DocsStoreService extends Service {
5858
5959 let fastboot = getOwner ( this ) . lookup ( 'service:fastboot' ) ;
6060 if ( fastboot ?. isFastBoot ) {
61- // In FastBoot, use Node's http module to fetch from the local server
62- // that prember/fastboot is running
63- let http = FastBoot . require ( 'http' ) ;
64- let request = fastboot . request ;
65- // Derive host and protocol from the FastBoot/Node request in a standards-based way
66- let host =
67- ( request &&
68- request . headers &&
69- ( request . headers . host || request . headers . Host ) ) ||
70- request . host ;
71- let protocol =
72- ( request && request . protocol ) ||
73- ( request &&
74- request . headers &&
75- ( request . headers [ 'x-forwarded-proto' ] ||
76- request . headers [ 'X-Forwarded-Proto' ] ) ) ||
77- 'http' ;
78- let url = `${ protocol } ://${ host } /docs/${ id } .json` ;
79-
80- let data = await new Promise ( ( resolve , reject ) => {
81- let req = http . get ( url , ( res ) => {
82- res . setEncoding ( 'utf8' ) ;
83- let body = '' ;
84- res . on ( 'data' , ( chunk ) => {
85- body += chunk ;
86- } ) ;
87- res . on ( 'end' , ( ) => {
88- let statusCode = res . statusCode || 0 ;
89- if ( statusCode >= 200 && statusCode < 300 ) {
90- resolve ( body ) ;
91- } else {
92- reject (
93- new Error ( `Request to ${ url } failed with status ${ statusCode } ` ) ,
94- ) ;
95- }
96- } ) ;
97- res . on ( 'error' , reject ) ;
98- } ) ;
99-
100- req . on ( 'error' , reject ) ;
101- // Basic timeout so prember/fastboot failures don't hang indefinitely
102- req . setTimeout ( 10000 , ( ) => {
103- req . abort ( ) ;
104- reject ( new Error ( `Request to ${ url } timed out` ) ) ;
105- } ) ;
106- } ) ;
107-
108- payload = JSON . parse ( data ) ;
61+ // In FastBoot, read the docs JSON directly from the dist directory
62+ // using FastBoot.distPath. This works during both prember builds and
63+ // ember serve with fastboot, without needing an HTTP request.
64+ let fs = FastBoot . require ( 'fs' ) ;
65+ let path = FastBoot . require ( 'path' ) ;
66+ let filePath = path . join ( FastBoot . distPath , 'docs' , `${ id } .json` ) ;
67+ payload = JSON . parse ( fs . readFileSync ( filePath , 'utf8' ) ) ;
10968 } else {
11069 let namespace = `${ getRootURL ( this ) . replace ( / \/ $ / , '' ) } /docs` ;
11170 let url = `${ namespace } /${ id } .json` ;
0 commit comments