in server.js [23:58]
static requestListener(request, response) {
if (request.method === 'GET') {
const url = new URL(request.url, Server.origin);
const filePath = path.resolve(`${root}/${url.pathname}`);
const fileExt = path.extname(filePath);
const mimeType = mimeLookup.get(fileExt);
if (fileExt) {
if (mimeType) {
fs.stat(filePath, (error, stats) => {
if (stats) {
Server.sendFile(response, filePath, mimeType, stats.size);
} else {
Server.sendFileNotFound(response);
}
});
} else {
Server.sendUnknownMimeType(response, fileExt);
}
} else {
if (url.pathname.endsWith('/')) {
const directoryIndex = `${filePath}/index.html`;
fs.stat(directoryIndex, (error, stats) => {
if (stats) {
Server.sendFile(response, directoryIndex, 'text/html', stats.size);
} else {
// @TODO pushState optional
Server.sendRootIndex(response);
}
});
} else {
Server.sendRedirect(response, `${url.pathname}/`);
}
}
}
}