Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function verifyPkg (t) {
const pkgFile = path.join(workdir, 'package.json')
readFile(pkgFile, function (err, data) {
t.error(err)
const pkg = JSON.parse(data)
t.equal(pkg.name, 'workdir')
t.equal(pkg.version, '1.0.0')
t.equal(pkg.description, '')
t.equal(pkg.author, '')
// by default this will be ISC but since we have a MIT licensed pkg file in upper dir, npm will set the license to MIT in this case
// so for local tests we need to accept MIT as well
t.ok(pkg.license === 'ISC' || pkg.license === 'MIT')
t.equal(pkg.scripts.test, 'tap test/**/*.test.js')
t.equal(pkg.scripts.start, 'fastify start -l info app.js')
t.equal(pkg.scripts.dev, 'fastify start -l info -P app.js')
t.equal(pkg.dependencies['fastify-cli'], '^' + cliPkg.version)
t.equal(pkg.dependencies['fastify'], cliPkg.dependencies.fastify)
t.equal(pkg.dependencies['fastify-plugin'], cliPkg.devDependencies['fastify-plugin'] || cliPkg.dependencies['fastify-plugin'])
t.equal(pkg.dependencies['fastify-autoload'], cliPkg.devDependencies['fastify-autoload'])
router.get(/(.*)/, function (req, res, next) {
req.params.page = req.params['0'];
if (req.params.page === '/') {
res.render('index', {
version: PACKAGE.version
});
} else {
var p = path.normalize('dist' + req.params.page)
if (p.startsWith('dist')) { // Allow access to ressources under 'dist' directory only.
fs.readFile(p, 'utf8', function (err, data) {
if (err) {
res.render('index', {
version: PACKAGE.version
});
} else {
res.contentType('text/html').end(data);
}
});
} else {
res.render('index', {
version: PACKAGE.version
});
}
}
});
request(remote, function downloading(err, res, remote) {
if (err) return callback(err)
if (res.statusCode !== 200)
return callback(new Error("Invalid statusCode returned"))
// Append get some local additions that are missing from the source
fs.readFile(after, "utf8", function reading(err, after) {
if (err) return callback(err)
// Parse the contents
parse([before, remote, after], function parsing(
err,
results,
source
) {
callback(err, results)
if (!source || err) return
//
// Save to a tmp file to avoid potential concurrency issues.
//
tmp.file((err, tempFilePath) => {
return new Promise((resolve, reject) => {
readFile(filePath, 'utf8', (error, raw) => {
if (error) {
reject(error)
} else {
const name = basename(filePath, extname(filePath))
const id = options.namespace ? `${options.namespace}/${name}` : name
Handlebars.registerPartial(id, raw)
resolve()
}
})
})
}
function subscribeMOTDFileChange ()
{
var commonUtils = require("../utils/common.utils");
var logutils = require('../utils/log.utils');
var config = getConfig();
var contents = null;
var filePath = null;
var motdFilePath =
commonUtils.getValueByJsonPath(config, "motd;file_path", "");
fs.readFile(motdFilePath, fileReadOptions, function(error, contents) {
if ((null != error) && (null != error.errno)) {
fs.readFile(defaultMotdFilePath, fileReadOptions, function(error, contents) {
if ((null != error) && (null != error.errno)) {
logutils.logger.error("Configured/Default MOTD file " +
"read error code", error.errno);
updateAndWatchMOTDFileChange(null, null);
return;
}
updateAndWatchMOTDFileChange(contents, defaultMotdFilePath);
return;
});
}
updateAndWatchMOTDFileChange(contents, motdFilePath);
});
return;
}
function renderTemplate(templatePath, outputPath, data){
fs.readFile(templatePath, function(err, template){
if (err) throw err;
var html = Mustache.to_html(template.toString(), data, partials);
fs.writeFile(outputPath, html, function(err){
if (err) throw err;
});
});
}
}
router.get('/', function(req, res, next) {
fs.readFile('./text/leaves-of-spam.txt', 'utf8', function(err, data) {
res.render('index', { title: "Big Dummy's Leaves of Spam", text: data} );
});
});
form.parse(req, (err, fields, files) => {
if (err) {
awesomeLog(req, 'form parse error');
return res.status(500).json({ message: 'An error occurred' });
}
if (!files || !files.image) {
awesomeLog(req, 'No image in upload');
return res.status(500).json({ message: 'An error occurred' });
}
const path = files.image.path;
const imgurRequest = request.defaults({ json: true });
fs.readFile(path, (e, img_data) => {
const temp = { uri: 'https://api.imgur.com/3/image', headers: { Authorization: `Client-ID ${config.get('imgurClientID')}` } };
temp.body = img_data.toString('base64');
imgurRequest.post(temp, (e, r, body) => {
if (e) {
awesomeLog(req, 'imgur post fail!');
awesomeLog(req, e);
awesomeLog(req, body);
return res.status(500).json({ message: 'An error occurred.' });
} if (!body) {
awesomeLog(req, 'imgur post fail!!');
awesomeLog(req, e);
return res.status(500).json({ message: 'An error occurred.' });
} if (r.statusCode !== 200 || body.error) {
awesomeLog(req, 'imgur post fail!!!');
awesomeLog(req, e);
awesomeLog(req, body);