本文介绍了在nodejs/express中,如何允许搜寻器使用站点地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在nodejs/express中,如何允许搜寻器使用站点地图?

In nodejs/express how to allow sitemap for crawler?

下面的代码是我的应用程序流程的一部分,应将Sitemap文件夹/文件放在哪里?以及如何允许搜寻器?现在访问domain/sitemap/sitemap.xml显示未找到.

Below code is part of my application flow, where should I put my sitemap folder/files? and how to allow for crawler ? right now visit domain/sitemap/sitemap.xml shows not found..

project/app/app.js

project/app/app.js

app.js

require('./RouteHandler.js')(app, express);

RouteHandler.js

RouteHandler.js

...
var routesIndex = require('./routes/Index/Base.js');
app.use('/', routesIndex);
...

module.exports = setupRoutes;

routes/Index/Base.js

routes/Index/Base.js

var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {
   render .. view
});
module.exports = router;

推荐答案

我们有一个类似的案例,我们以这种方式解决了.

we had a similar case, and we resolved it this way.

  • 编写一个单独的js文件,该文件在需要时呈现xml文件,并将其保存到目录中,以免您的主要Web事件循环变得越来越久.
  • 假设文件夹名称为sitemap,文件为sitemap.xml,则可以用这种方式声明静态文件

  • write a separate js file that renders the xml files when needed and save it to a directory, cleaning your main web event loop from getting any longer.
  • lets assume the folder name is sitemap, and the file is sitemap.xml, you can declare a static file in express this way

app.use(express.static('sitemap'));

app.use(express.static('sitemap'));

或者,我建议让网络服务器来执行此操作,以使请求甚至不会发送到您的应用程序,对我来说,我使用的是nginx

OR, as I recommend to let a web server do it so the request doesn't even make it to your app, for me, I use nginx

位置/站点地图 { 根目录/dir/to/app/dir/sitemap; }我希望这会有所帮助:)

location /sitemap { root /dir/to/app/dir/sitemap; }I hope this helps :)

这篇关于在nodejs/express中,如何允许搜寻器使用站点地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 11:15