Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 使用google app engine在vue上进行社交预览_Google App Engine_Google Cloud Platform_Single Page Application - Fatal编程技术网

Google app engine 使用google app engine在vue上进行社交预览

Google app engine 使用google app engine在vue上进行社交预览,google-app-engine,google-cloud-platform,single-page-application,Google App Engine,Google Cloud Platform,Single Page Application,我们有一个单页应用程序(vue),我们正试图为其生成具有动态数据的社交预览。除了Facebook,社交预览在任何地方都可以使用 web服务器是在GCP应用程序引擎上提供的node+express应用程序 每个get请求都会根据用户代理进行筛选 如果用户代理是爬虫程序,则使用元数据为服务器生成的页面提供服务 否则,如果用户代理不是爬虫程序,则为我们的单页应用程序(index.html)提供服务 如果web服务器在本地运行,facebook爬虫程序就可以获得正确的页面 但是,当托管在GCP上时,如果

我们有一个单页应用程序(vue),我们正试图为其生成具有动态数据的社交预览。除了Facebook,社交预览在任何地方都可以使用

web服务器是在GCP应用程序引擎上提供的node+express应用程序

每个get请求都会根据用户代理进行筛选
如果用户代理是爬虫程序,则使用元数据为服务器生成的页面提供服务
否则,如果用户代理不是爬虫程序,则为我们的单页应用程序(index.html)提供服务

如果web服务器在本地运行,facebook爬虫程序就可以获得正确的页面
但是,当托管在GCP上时,如果facebook爬虫获得/xyz,则日志显示它也在/xyz之前获得/(在根目录中),并且facebook爬虫获得两个URL,从而导致爬虫中的条目不正确

日志显示:

获取/(无用户代理)
GET/xyz(爬虫用户代理)
第一次得到是错误的,不应该发生
只发生在GCP上

这是代码,删除了不相关的部分:

const express=require('express'))
const path=require('path');
const port=process.env.port | | 8081;
const app=express()
const nonSPArouter=express.Router();
const axios=require('axios');
常量压缩=需要(“压缩”);
app.use(compression());
nonSPArouter.get(“/:roomId/”,函数(请求,响应){
log(request.params.roomId,request.headers['user-agent']);
get(FIREBASE_URL+request.params.roomId+'.json')
。然后(firebaseResponse=>{
//获取特定于房间的数据
...
response.render('bot'{
img:img,
url:url,
标题:标题,,
descriptionText:descriptionText,
imageUrl:img
});
console.log(“服务于bot”,标题);
}).catch(错误=>{
控制台错误(error);
});
});
//正常使用静态资产
应用程序使用(express.static(u dirname+/dist');
//使用index.html处理其他每一条路由,其中将包含
//应用程序JavaScript文件的脚本标记。
app.get('*',函数(请求,响应){
让userAgent=request.headers['user-agent'];
log(`${request.url}用户代理:${userAgent}`);
如果(/^(facebook外部点击)|(Twitterbot)|(Pinterest)|(Discordbot)|(LinkedInBot)|(SkypeUriPreview)|(WhatsApp)/gi.test(userAgent)){
非共享者(请求、响应);
}否则{
log('service index to',request.headers['user-agent']);
sendFile(path.resolve(_dirname,'dist/index.html');
}
});
应用程序集(“查看引擎”、“翡翠”);
const server=app.listen(端口,()=>{
const host=server.address().address;
const port=server.address().port;
log(`Webserver在http://${host}:${port}`侦听)
})
这是GCP上的日志在使用facebook的爬虫程序手动执行请求后显示的内容,绿色框表示预期的行为,红色框显示facebook爬虫程序的实际服务内容:

大家好,欢迎来到stackoverflow。如果我们能看到进行区分的代码片段,我们会更容易得到帮助:)这种行为有点奇怪,可能是应用程序引擎不恰当地隐藏了某些内容,这就是为什么我认为您应该在中打开一个报告,以便对此进行检查。