Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions servor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = async ({
// Server utility functions

const isRouteRequest = (pathname) => !~pathname.split('/').pop().indexOf('.');
const isDir = (pathname) => fs.existsSync(pathname.split('/').pop()) && fs.lstatSync(pathname.split('/').pop()).isDirectory();
const utf8 = (file) => Buffer.from(file, 'binary').toString('utf8');

const baseDoc = (pathname = '', base = path.join('/', pathname, '/')) =>
Expand Down Expand Up @@ -156,6 +157,7 @@ module.exports = async ({
const pathname = path.normalize(decodePathname).replace(/^(\.\.(\/|\\|$))+/, '');
res.setHeader('access-control-allow-origin', '*');
if (reload && pathname === '/livereload') return serveReload(res);
if (!isRouteRequest(pathname) && isDir(pathname)) return serveRoute(res, pathname);
if (!isRouteRequest(pathname)) return serveStaticFile(res, pathname);
return serveRoute(res, pathname);
}).listen(parseInt(port, 10));
Expand Down