预渲染呈现了错误的网址

时间:2019-05-16 10:12:20

标签: angularjs prerender

我有AngularJS和Express项目。 AngularJS用于前端,expressJS用于服务器。两者都是独立的项目,并且URL也不同。当我在expressJS中安装中间件时,它会收到错误的Express域URL。

ExpressJS

var prerender = require('prerender-node');
prerender.set('prerenderToken', 'MY_TOKEN');
prerender.crawlerUserAgents.push('googlebot');
app.use(prerender);

带有Nginx Conf的AngularJS

server {
    listen 80;
    sendfile off;
    expires 0;
    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri @prerender $uri/ /index.html =404;

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';
    }

    location @prerender {
        proxy_set_header X-Prerender-Token MY_TOKEN;

        set $prerender 0;
        if ($http_user_agent ~* "googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
            set $prerender 1;
        }
        if ($args ~ "_escaped_fragment_") {
            set $prerender 1;
        }
        if ($http_user_agent ~ "Prerender") {
            set $prerender 0;
        }
        if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
            set $prerender 0;
        }

        #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
        resolver 8.8.8.8;

        if ($prerender = 1) {

            #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
            set $prerender "service.prerender.io";
            rewrite .* /$scheme://$host$request_uri? break;
            proxy_pass http://$prerender;
        }
        if ($prerender = 0) {
            rewrite .* /index.html break;
        }
    }
}

问题

ExpressJS在http://api.example.com上运行,而AngularJS在http://www.example.com上运行

Prerender io收到http://api.example.com,应该是http://api.example.com

0 个答案:

没有答案