@@ -6,8 +6,6 @@ import http, { STATUS_CODES } from 'http'
6
6
import {
7
7
renderToHTML ,
8
8
renderErrorToHTML ,
9
- renderJSON ,
10
- renderErrorJSON ,
11
9
sendHTML ,
12
10
serveStatic ,
13
11
renderScript ,
@@ -124,16 +122,20 @@ export default class Server {
124
122
const error = new Error ( 'INVALID_BUILD_ID' )
125
123
const customFields = { buildIdMismatched : true }
126
124
127
- await renderScriptError ( req , res , page , error , customFields , this . renderOpts )
128
- return
125
+ return await renderScriptError ( req , res , page , error , customFields , this . renderOpts )
129
126
}
130
127
131
128
if ( this . dev ) {
129
+ try {
130
+ await this . hotReloader . ensurePage ( page )
131
+ } catch ( error ) {
132
+ return await renderScriptError ( req , res , page , error , { } , this . renderOpts )
133
+ }
134
+
132
135
const compilationErr = this . getCompilationError ( page )
133
136
if ( compilationErr ) {
134
137
const customFields = { buildError : true }
135
- await renderScriptError ( req , res , page , compilationErr , customFields , this . renderOpts )
136
- return
138
+ return await renderScriptError ( req , res , page , compilationErr , customFields , this . renderOpts )
137
139
}
138
140
}
139
141
@@ -257,40 +259,6 @@ export default class Server {
257
259
return this . renderError ( null , req , res , pathname , query )
258
260
}
259
261
260
- async renderJSON ( req , res , page ) {
261
- if ( this . dev ) {
262
- const compilationErr = this . getCompilationError ( page )
263
- if ( compilationErr ) {
264
- return this . renderErrorJSON ( compilationErr , req , res )
265
- }
266
- }
267
-
268
- try {
269
- return await renderJSON ( req , res , page , this . renderOpts )
270
- } catch ( err ) {
271
- if ( err . code === 'ENOENT' ) {
272
- res . statusCode = 404
273
- return this . renderErrorJSON ( null , req , res )
274
- } else {
275
- if ( ! this . quiet ) console . error ( err )
276
- res . statusCode = 500
277
- return this . renderErrorJSON ( err , req , res )
278
- }
279
- }
280
- }
281
-
282
- async renderErrorJSON ( err , req , res ) {
283
- if ( this . dev ) {
284
- const compilationErr = this . getCompilationError ( '/_error' )
285
- if ( compilationErr ) {
286
- res . statusCode = 500
287
- return renderErrorJSON ( compilationErr , req , res , this . renderOpts )
288
- }
289
- }
290
-
291
- return renderErrorJSON ( err , req , res , this . renderOpts )
292
- }
293
-
294
262
async serveStatic ( req , res , path ) {
295
263
try {
296
264
return await serveStatic ( req , res , path )
@@ -303,10 +271,6 @@ export default class Server {
303
271
}
304
272
}
305
273
306
- serveScript ( req , res , path ) {
307
- return serveStatic ( req , res , path )
308
- }
309
-
310
274
readBuildId ( ) {
311
275
const buildIdPath = join ( this . dir , '.next' , 'BUILD_ID' )
312
276
const buildId = fs . readFileSync ( buildIdPath , 'utf8' )
0 commit comments