我创建了一个服务类并将其设为单例:
class DiscordService {
async getToken(code) {
const creds = btoa(`${process.env.DISCORD_CLIENT_ID}:${process.env.DISCORD_SECRET}`);
const headers = {
Authorization: `Basic ${creds}`,
};
const baseUrl = 'https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=';
const url = `${baseUrl}${code}&redirect_uri=${process.env.DISCORD_CALLBACK_URL}`;
const response = await axios.post(url, {}, {headers});
return await response.data;
}
}
export default new DiscordService();
我已将该类导入我的路由文件discord.js
import DiscordService from '../services/discord';
我正在像这样使用它
const response = await DiscordService.getToken(code);
运行服务器时,出现以下错误:
import DiscordService from '../services/discord';
^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
是因为只允许输入打字稿吗?还是我需要通天塔?