Angular SEO / NodeJS / PhantomJS - Serve static html files

I am implementing my own PhantomJS solution to provide snapshots to crawlers.

When the crawler comes in, url / #! / Is transformed like this: http://example.com/?_escaped_fragment_=/a/b/c

I want to use static files from / public / snapshots for the crawler when it crawls one of my pages.

Current solution

I intercept URLs and rewrite this:

It comes to a route in my NodeJS where I get the name of the html file according to the url parameters. In this case, it would be /snapshots/a/b/c.html

I get the file with:

fs.readFile(file_path, function(err, content)
{
    res.set('Content-Type', 'text/html');
    res.send(content);
});

      

Problem

When I set Content-Type to HTML Angular / Express does a redirect and my url gets this:

If I go to this URL, I can see the correct snapshot file /a/b/c.html, but after a few milliseconds, I am redirected to my home page.

Questions

thank

+3


source to share





All Articles