1

I have setup a server with Express.js:

const env = process.env.ENV || 'PROD';
const port = process.env.PORT || 8080;
const express = require('express');
const app = express();

if(env === 'PROD') {
    app.all('*', function(req, res, next) {
        var protocol = req.headers['x-forwarded-proto'];
        if(protocol && protocol === 'http') {
            res.redirect(301, 'https://' + req.headers.host + req.url);
        }
        return next();
    });
}

app.use(require('prerender-node').set('prerenderToken', 'mytoken'));

app.use(express.static(__dirname + '/app/'));

app.get('*', function(req, res){
    res.sendFile(__dirname + '/app/index.html');
});

app.listen(port);
console.log("App started on port "+port);

In angularjs app set config:

config(['$locationProvider', '$routeProvider', function ($locationProvider, $routeProvider) {
    $locationProvider.html5Mode(true);
}])

In index.html:

<meta name="fragment" content="!">

As documentation says: https://prerender.io/documentation/test-it

I do:

http://mydomainm/user/1?_escaped_fragment_=

But my page not cached. enter image description here

2 Answers 2

2

So it looks like the middleware is working properly but you are sending us an http URL so we are returning a 301. Can you modify your middleware to be like this:

app.use(require('prerender-node').set('prerenderToken', 'mytoken').set('protocol', 'https'));

That should fix that redirect issue and get everything working properly.

Sign up to request clarification or add additional context in comments.

Comments

0

That looks like it should be working properly. Can you send an email to [email protected] so that we can check your Crawl Stats and do some testing on our end? Thanks!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.