我正在制作Office加载项,并且试图访问我的Node服务器,我启用了CORS,但仍然无法正常工作,请帮助:
服务器代码:
const server = Restify.createServer();
const port: string = process.env.port || process.env.PORT || "5512";
server.listen(process.env.port || process.env.PORT || 5512, () => {
console.log("Bot Server on port " + port);
});
server.use(Restify.plugins.bodyParser());
server.use(Restify.plugins.queryParser());
server.use(
function crossOrigin(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
return next();
},
);
server.get("/", (req: Restify.Request, res: Restify.Response) => {
res.send("AAE Relay Server is up.");
});
Office加载项代码:
$.ajax({
type: "POST",
dataType: "json",
url: "https://server.azurewebsites.net/ping",
data: JSON.stringify({...}),
crossDomain: true,
contentType: "application/json",
})
.done(function (data) {
...
})
.fail(function (jqXHR, textStatus, errorThrown) {
...
})
.always(function () {
...
});
我没有收到任何特定的错误,只是说“错误”。
我在做什么错了?