How do make the server reload the Dirty database when it's trying to get something from it? Because when I edit the database file with a text editor, and reload the browser, it doesn't update the page.
"reloadDB();" is where I want to reload the db. Code example
http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
var html = db.get(pathname);
//Check if the requsted file is CSS or JS
if (/\.(css)$/.test(pathname) || /\.(js)$/.test(pathname)){
fs.createReadStream(__dirname + pathname, {
'bufferSize': 4 * 1024
}).pipe(response);
} else if (!!html && pathname !== '/admin' ) {
//Pages from our Dirty DB
response.writeHead(200, {'Content-Type': 'text/html'});
//reloadDB();
response.end(html);
} else if (pathname === '/admin') {
//Display Admin page
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('Admin!');
} else {
//Show 404 Page
response.writeHead(404, {'Content-Type': 'text/html'});
//reloadDB();
response.end(db.get('404'));
}
You just need to call the .Dirty(path)
method of your existing instance; if you look at the source, you'll see that there's a check allowing Dirty()
to be used as either an instance method or a constructor.