1
- /* eslint-disable max-lines-per-function, max-lines */
2
1
const { promises, createWriteStream, existsSync } = require ( 'fs' )
3
2
const { Server } = require ( 'http' )
4
3
const { tmpdir } = require ( 'os' )
@@ -35,8 +34,6 @@ const makeHandler =
35
34
const cacheDir = path . join ( tmpdir ( ) , 'next-static-cache' )
36
35
// Grab the real fs.promises.readFile...
37
36
const readfileOrig = promises . readFile
38
- const writeFileOrig = promises . writeFile
39
- const mkdirOrig = promises . mkdir
40
37
// ...then money-patch it to see if it's requesting a CDN file
41
38
promises . readFile = async ( file , options ) => {
42
39
// We only care about page files
@@ -45,10 +42,6 @@ const makeHandler =
45
42
const filePath = file . slice ( pageRoot . length + 1 )
46
43
const cacheFile = path . join ( cacheDir , filePath )
47
44
48
- if ( existsSync ( cacheFile ) ) {
49
- return readfileOrig ( cacheFile , options )
50
- }
51
-
52
45
// Is it in the CDN and not local?
53
46
if ( staticFiles . has ( filePath ) && ! existsSync ( file ) ) {
54
47
// This name is safe to use, because it's one that was already created by Next
@@ -74,27 +67,6 @@ const makeHandler =
74
67
75
68
return readfileOrig ( file , options )
76
69
}
77
-
78
- promises . writeFile = async ( file , data , options ) => {
79
- if ( file . startsWith ( pageRoot ) ) {
80
- const filePath = file . slice ( pageRoot . length + 1 )
81
- const cacheFile = path . join ( cacheDir , filePath )
82
- await promises . mkdir ( path . dirname ( cacheFile ) , { recursive : true } )
83
- return writeFileOrig ( cacheFile , data , options )
84
- }
85
-
86
- return writeFileOrig ( file , data , options )
87
- }
88
-
89
- promises . mkdir = async ( dir , options ) => {
90
- if ( dir . startsWith ( pageRoot ) ) {
91
- const filePath = dir . slice ( pageRoot . length + 1 )
92
- const cachePath = path . join ( cacheDir , filePath )
93
- return mkdirOrig ( cachePath , options )
94
- }
95
-
96
- return mkdirOrig ( dir , options )
97
- }
98
70
}
99
71
let NextServer
100
72
try {
@@ -210,4 +182,3 @@ exports.handler = ${
210
182
`
211
183
212
184
module . exports = getHandler
213
- /* eslint-enable max-lines-per-function, max-lines */
0 commit comments