angularjs - Prerender.io 不缓存我的页面

标签 angularjs node.js express seo prerender

所以我正在尝试设置 prerender.io对于我的带有 ExpressJS 后端的 AngularJS 应用程序,遵循此 tutorial .我完全按照指示做了,唯一的区别是我启用了 HTML5mode .我已经包含了 meta(name="fragment" content="!")在我的 index.jade和我的 server.js 的预呈现 token 文件(使用 prerender-node 包),但不知何故我的页面似乎没有被缓存或生成任何抓取统计信息。

config.coffee

angular.config ['$stateProvider','$urlRouterProvider','$locationProvider','toastrConfig',($stateProvider, $urlRouterProvider,$locationProvider,toastrConfig)->
    $stateProvider
    .state 'home',
        url:'/'
        templateUrl: 'html/main.html'
        controller:'mainController'

    $urlRouterProvider.otherwise '/'

    $locationProvider.html5Mode
        enabled: true
        requireBase: false

    $locationProvider.hashPrefix '!'
]

Server.JS

// Here we require the prerender middleware that will handle requests from Search Engine crawlers 
// We set the token only if we're using the Prerender.io service 
app.use(require('prerender-node')
.set('prerenderServiceUrl', 'http://www.mydomain.co.com/')
.set('prerenderToken', 'my-token'));


// HTML5MODE settings
// ------------------------------------------------------
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/html', express.static(__dirname + '/public/html'));

// Routes
// ------------------------------------------------------
require('./app/js/routes/routes.js')(app);

app.all('/*', function(req, res, next) {
    // Just send the index.html for other files to support HTML5Mode
    res.sendFile('/public/index.html', { root: __dirname });
});

最佳答案

你应该从你的配置中删除这一行:

.set('prerenderServiceUrl', 'http://www.mydomain.co.com/')

服务 URL 应指向 Prerender 服务器,因此您不应将其设置为您的网站 URL。

关于angularjs - Prerender.io 不缓存我的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37319412/

相关文章:

javascript - 使用 Angular 在顶部添加行 - Xeditable

html - 在单页应用程序中将页脚设置为底部

jquery - 在 Node js Rest Web api 中无法获取请求正文

javascript - Sequelize : how to update with associations?

javascript - Angular JS HTTP Post 不起作用

javascript - 是否可以在 AngularJS 应用程序中使用 Typescript?

javascript - 警告 - 未处理的 promise 拒绝 : Can't set headers after they are sent

javascript - 错误 : Cannot find module './lib/mediaType' "(after successful login)

node.js - Connect Memory Store——解决它对 Node Web 服务器的生产限制

javascript - 使用 EJS 将 MySQL 查询结果显示为 HTML