Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
w.bundle()
.on('error', function(err) {
console.error(colors.red('\nError: ') + err.message);
res.end('console.error("' + err.message + '")');
this.emit('end');
})
.pipe(res);
});
// static files
server.use(serveStatic(directory));
server.use(serveIndex(directory));
// livereload server
if (process.env.NODE_ENV !== 'production') {
server.use(livereloadServer.middleware({ app: server }));
}
// start the server
server.listen(process.env.PORT || program.port, function () {
var htmlFile = (projectType === 'module') ? 'test.html' : '';
console.log(
colors.grey('%s running at ') + colors.cyan('http://localhost:%s/%s'),
projectType.charAt(0).toUpperCase() + projectType.slice(1),
program.port,
htmlFile
);
exec('open "http://localhost:' + program.port + '/' + htmlFile + '"');
});
console.log(`You are in ${process.env.NODE_ENV} mode`)
console.log(
'which means every change in your themes (templates, partials and assets), reference and structure folders will dynamically update your site'
)
console.log("In production, this mode shouldn't be used.")
this._watchersStart()
var lport = process.env.LIVERELOAD_PORT || 35729
this.lserver = express()
// Launching a Livereload server
this.lserver
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.use(tinylr.middleware({app: this.lserver}))
.listen(lport, function() {
console.log('Livereload listening on %d', lport)
})
.on('error', function(err) {
if (err.code == 'EADDRINUSE') {
console.error(
clc.red("can't start the Abe's watch server\n"),
`This watch server has tried to listen on the port ${lport} but this server is already in use by another process...`
)
} else {
console.error(err)
}
})
process.on('SIGINT', () => {
try {
var server = express();
var startFileWatcher = function() {
var watcher = chokidar.watch(assetPath + '/**/*');
watcher.on('ready', function(){
console.log('Livereload enabled. Watching for changes in', assetPath);
watcher.on('all', function(event, path) {
tinylr.changed(path)
});
});
};
if(livereload) {
server
.use(tinylr.middleware({ app: server, dashboard: true }))
.use(require('connect-livereload')({
src: '/livereload.js?snipver=1',
include: [ '/', '.*\.html']
}));
}
if(cors) {
server.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', req.get('Access-Control-Request-Headers') || '*');
next();
});
}
server
.use(express.static(assetPath, {