Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (cacheValue > 0) {
streamOptions.maxAge = flags.cache;
} else if (cacheValue === 0) {
// Disable the cache control by `send`, as there's no support for `no-cache`.
// Set header manually.
streamOptions.cacheControl = false;
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
} else if (flags.single) {
// Cache assets of single page applications for a day.
// Later in the code, we'll define that `index.html` never
// gets cached!
streamOptions.maxAge = 86400000;
}
// Check if directory
if (relatedExists && (yield pathType.dir(related))) {
// Normalize path to trailing slash
// Otherwise problems like #70 will occur
const url = parse(req.url);
if (url.pathname.substr(-1) !== '/') {
url.pathname += '/';
const newPath = format(url);
res.writeHead(302, {
Location: newPath
});
res.end();
return;
}
module.exports = (fp, opts) => {
if (typeof fp !== 'string') {
opts = fp;
fp = '.';
}
opts = opts || {};
return pathType.dir(fp)
.then(isDir => {
if (isDir) {
fp = path.join(fp, 'package.json');
}
return loadJsonFile(fp);
})
.then(x => {
if (opts.normalize !== false) {
require('normalize-package-data')(x);
}
return x;
});
};
) {
const details = server.address();
const {isTTY} = process.stdout;
const shutdown = () => {
server.close();
process.exit(0);
};
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
let isDir;
try {
isDir = yield pathType.dir(current);
} catch (err) {
isDir = false;
}
if (!isDir) {
const base = basename(current);
console.error(
chalk.red(`Specified directory ${chalk.bold(`"${base}"`)} doesn't exist!`)
);
process.exit(1);
}
if (process.env.NODE_ENV !== 'production') {
let message = chalk.green('Serving!');
}
try {
files = yield fs.readdir(dir);
} catch (err) {
throw err;
}
for (const file of files) {
const filePath = path.resolve(dir, file);
const index = files.indexOf(file);
const details = path.parse(filePath);
details.relative = path.join(subPath, details.base);
if (yield pathType.dir(filePath)) {
details.base += '/';
} else {
details.ext = details.ext.split('.')[1] || 'txt';
let fileStats;
try {
fileStats = yield fs.stat(filePath);
} catch (err) {
throw err;
}
details.size = filesize(fileStats.size, {round: 0});
}
details.title = details.base;
module.exports = function (fp, opts) {
if (typeof fp !== 'string') {
opts = fp;
fp = '.';
}
opts = opts || {};
return pathType.dir(fp)
.then(function (isDir) {
if (isDir) {
fp = path.join(fp, 'package.json');
}
return loadJsonFile(fp);
})
.then(function (x) {
if (opts.normalize !== false) {
normalizePackageData(x);
}
return x;
});
};
module.exports = (fp, opts) => {
if (typeof fp !== 'string') {
opts = fp;
fp = '.';
}
opts = opts || {};
return pathType.dir(fp)
.then(isDir => {
if (isDir) {
fp = path.join(fp, 'package.json');
}
return loadJsonFile(fp);
})
.then(x => {
if (opts.normalize !== false) {
require('normalize-package-data')(x);
}
return x;
});
};
module.exports = function (fp, opts) {
if (typeof fp !== 'string') {
opts = fp;
fp = '.';
}
opts = opts || {};
return pathType.dir(fp)
.then(function (isDir) {
if (isDir) {
fp = path.join(fp, 'package.json');
}
return loadJsonFile(fp);
})
.then(function (x) {
if (opts.normalize !== false) {
normalizePackageData(x);
}
return x;
});
};
return Promise.all(arrify(input).map(x => pathType.dir(getPath(x))
.then(isDir => isDir ? getGlob(x, opts) : x)))
.then(globs => [].concat.apply([], globs));
return Promise.all(arrify(input).map(x => pathType.dir(getPath(x))
.then(isDir => isDir ? getGlob(x, opts) : x)))
.then(globs => [].concat.apply([], globs));