Skip to content

Better error message in case of missing assets on the local Dev server #17

Closed
@TysonMN

Description

@TysonMN

Consider this function

app.get(`${config.dest.namespace}/*`, (req, res) => {
const normalUrl = req.originalUrl.substr(config.dest.namespace.length).split('?')[0];
const filename = (normalUrl === '/' ? 'index' : normalUrl) + '.html';
const filepath = join(root, config.dest.html, filename);
res.sendFile(filepath, {}, err => {
if (err) {
if (!built) {
compile(buildingHtml)
.serialize()
.then(html => res.status(200).send(html));
}
else {
console.log(chalk.red('# Not Found::'));
console.log(chalk.red('# ') + req.originalUrl);
console.log(chalk.red('# ') + chalk.gray(filepath));
console.log();
res.sendFile(join(root, config.dest.html, _dropExt(config.src.not_found) + '.html'), {}, err => {
if (err) res.status(404).send('Not Found!!');
});
}
}
});
});

but especially line 43

const filename = (normalUrl === '/' ? 'index' : normalUrl) + '.html';

Is it correct that '.html' is always being appended to that file name?

I am playing around with the configuration and sometimes I get it wrong. Here is what one of the "Not Found::" error messages looks like for me.

# Not Found::
# /generated/bundle/codedoc-bundle.js
# C:\Code\Blogs\tyson-williams-blog\generated\generated\bundle\codedoc-bundle.js.html

2020-06-09_21-01-29_119_mintty

On the topic of error messages, where are those beautiful colors? My error message doesn't have any red in it :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions