Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.get('/*', (req, res, next) => {
if (req.hostname.startsWith('www.')){
const host: string = req.headers.host as string;
res.redirect(httpstatus.MOVED_PERMANENTLY,
'https://' + host.substr(4) + req.url);
}
else {
next();
}
});
}
fileServer.serve(request, response, function(err, res) {
if (err) {
if (options.redirects[request.url]) {
log(chalk.yellow("[" + HTTPStatus.MOVED_PERMANENTLY + "] " + request.url + " > " + options.redirects[request.url]), true);
response.writeHead(HTTPStatus.MOVED_PERMANENTLY, {"Location": options.redirects[request.url]});
response.end(HTTPStatus[HTTPStatus.MOVED_PERMANENTLY]);
}
else if (err.status && options.http_error_files && options.http_error_files[err.status]) {
log(chalk.yellow("[" + err.status + "] " + request.url + " - served: " + options.http_error_files[err.status]), true);
fileServer.serveFile(options.http_error_files[err.status], err.status, {}, request, response);
}
else {
log(chalk.red("[" + err.status + "] " + request.url), true);
response.writeHead(err.status, err.headers);
response.end(HTTPStatus[err.status]);
}
} else if (options.verbose) {
log("[" + response.statusCode + "] " + request.url, true);
}
});
fileServer.serve(request, response, function(err, res) {
if (err) {
if (options.redirects[request.url]) {
log(chalk.yellow("[" + HTTPStatus.MOVED_PERMANENTLY + "] " + request.url + " > " + options.redirects[request.url]), true);
response.writeHead(HTTPStatus.MOVED_PERMANENTLY, {"Location": options.redirects[request.url]});
response.end(HTTPStatus[HTTPStatus.MOVED_PERMANENTLY]);
}
else if (err.status && options.http_error_files && options.http_error_files[err.status]) {
log(chalk.yellow("[" + err.status + "] " + request.url + " - served: " + options.http_error_files[err.status]), true);
fileServer.serveFile(options.http_error_files[err.status], err.status, {}, request, response);
}
else {
log(chalk.red("[" + err.status + "] " + request.url), true);
response.writeHead(err.status, err.headers);
response.end(HTTPStatus[err.status]);
}
} else if (options.verbose) {
log("[" + response.statusCode + "] " + request.url, true);