Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
watchPath = watchPath || process.cwd();
options = options || {};
options.config = options.config || getBrunchConfigPath(watchPath, options);
options.server = true;
options.network = true;
const optionsFile = require(options.config);
logger.log(`Watching "${watchPath}" …`);
// Copy the server URL to the user's clipboard.
const port = (optionsFile.server && optionsFile.server.port) || 3333;
const https = options.https || options.ssl || options.secure || false;
const serverUrl = `http${https ? 's' : ''}://localhost:${port}/`;
try {
const watcher = brunch.watch(options, () => {
// saves preview videos from recorder component.
watcher.server.on('request', function (req, res) {
const method = req.method.toLowerCase();
const pathname = url.parse(req.url).pathname;
if (method === 'post' && pathname === '/upload') {
let form = new formidable.IncomingForm();
let files = [];
form.encoding = 'binary';
form.keepExtensions = true;
form.multiple = true;
const uploadDir = path.join(watchPath, 'app/assets/video/');
fs.ensureDir(uploadDir);
return new Promise((resolve, reject) => {
filePath = filePath || process.cwd();
options = options || {};
options.config = options.config || getBrunchConfigPath(filePath, options);
logger.log(`Building project "${filePath}" …`);
try {
brunch.build(options, resolve);
} catch (err) {
logger.error(`Could not build project "${filePath}" …`);
throw err;
}
}).then(() => {
let builtPath = null;