1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Remove the use of fs.access (#625)

This commit is contained in:
Arunoda Susiripala 2017-01-02 16:50:01 -08:00 committed by Guillermo Rauch
parent 01a17738db
commit 6d6ef1ca9f

View file

@ -1,7 +1,6 @@
import { join } from 'path'
import { createElement } from 'react'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import fs from 'mz/fs'
import send from 'send'
import accepts from 'accepts'
import requireModule from './require'
@ -150,16 +149,11 @@ export async function serveStaticWithGzip (req, res, path) {
try {
const gzipPath = `${path}.gz`
// fs.access before a file read is not recommeded due to race conditions.
// But in this case, this is totally fine because we know
// it's impossible to have a race condition like that.
// (Since we gzip AOT when called `next build`)
await fs.access(gzipPath, fs.constants.R_OK)
res.setHeader('Content-Encoding', 'gzip')
return serveStatic(req, res, gzipPath)
await serveStatic(req, res, gzipPath)
} catch (ex) {
if (ex.code === 'ENOENT') {
res.removeHeader('Content-Encoding')
return serveStatic(req, res, path)
}
throw ex