从nodejs调用将js文件包含到html文件中时获取MIME类型

时间:2018-08-24 06:23:13

标签: javascript node.js

server.js

var express = require('express');
var OAuth = require('oauth').OAuth;
var url = require('url');
var app = express();


const requestURL = "https://trello.com/1/OAuthGetRequestToken";
const accessURL = "https://trello.com/1/OAuthGetAccessToken";
const authorizeURL = "https://trello.com/1/OAuthAuthorizeToken";
const appName = "Trello OAuth Example";
const key = myAPIkey;
const secret = myTrelloSecret;
const loginCallback = "https://{my-host-name}/callback";
const oauth_secrets = {};

const oauth = new OAuth(requestURL, accessURL, key, secret, "1.0A", 
loginCallback, "HMAC-SHA1")

const login = function(request, response) {
oauth.getOAuthRequestToken(function(error, token, tokenSecret, results){
oauth_secrets[token] = tokenSecret;
response.redirect(`${authorizeURL}?oauth_token=${token}&name=${appName}`);
});
};

var callback = function(req, res) {
const query = url.parse(req.url, true).query;
const token = query.oauth_token;
const tokenSecret = oauth_secrets[token];
const verifier = query.oauth_verifier;
oauth.getOAuthAccessToken(token, tokenSecret, verifier, function(error, 
accessToken, accessTokenSecret, results){
trelloToken=accessToken;
trelloTokenSecret=accessTokenSecret;
res.sendFile(__dirname + '/views/index.html');
});
};

app.get('/', function(request, response) {
login(request, response);
});

app.get("/callback", function (request, response) {
callback(request, response);
});


var listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});

index.html

<html>
<head>
<title>A Trello Dashboard</title>
<script src="https://p.trellocdn.com/power-up.min.js"></script>
<script src="./../public/client.js"></script>
</head>
<body>
</body>
</html>

这是我的代码。运行此程序时出现类似

的错误

”拒绝从“ https:// {my-host-name} /public/client.js”执行脚本,因为其MIME类型(“ text / html”)不可执行,并且启用了严格的MIME类型检查。”

有人可以帮助我吗?

0 个答案:

没有答案