我正在尝试从我的无服务器脱机项目中获取HTML响应,但是它返回用双引号引起来的html正文,这会破坏页面。我如何摆脱报价?
内容类型看起来有效
我已安装此版本的无服务器插件
"serverless-base-path-plugin": "0.0.1",
"serverless-cors-plugin": "^0.2.1",
"serverless": "1.71.3",
"serverless-offline": "6.1.7",
"serverless-optimizer-plugin": "^1.0.0",
"serverless-resources-validation-plugin": "^0.2.0",
"serverless-helpers-js": "0.2.0",
"serverless-webpack": "5.3.2",
serverless.yml
provider:
name: aws
runtime: nodejs8.10
region: eu-west-1
profile: default
memorySize: 256 # optional, in MB, default is 1024
stage: local
plugins:
- serverless-offline
custom:
serverless-offline:
host: 0.0.0.0
httpPort: 1465
useDocker: false
noPrependStageInUrl: true
functions:
xdomainProxy:
handler: dist/xdomain-proxy/handler.handler
events:
- http:
path: /api/xdomain-proxy
method: get
integration: lambda
response:
headers:
Content-Type: "'text/html'"
handler.js
'use strict';
var ServerlessHelpers = require('serverless-helpers-js').loadEnv(); // all content must be assembled into a single variable
function render() {
return ['<!DOCTYPE HTML>', '<link rel="shortcut icon" href="about:blank">', '<script src="https://cdn.rawgit.com/jpillora/xdomain/0.7.4/dist/xdomain.min.js"></script>'].join(' ');
} // Lambda Handler
module.exports.handler = function (event, context) {
try {
var html = render();
context.succeed(html);
} catch (err) {
console.log(err);
context.fail(err);
}
};
好,看起来像是无服务器脱机版本6。如果您尝试返回字符串,我可以发现它运行json.stringify。降级到版本5为我解决了这个问题。