我正在尝试使用离子存储中的令牌从服务器获取数据。我遇到的问题是,获取令牌承诺不能按时检索令牌。因此,每当我重新加载或重新打开该应用程序时,有时都会返回未经授权的错误。
仪表板service.ts
authUrl = "https://sampleapi.herokuapp.com"
authHeaders;
getToken() {
this.storage.get('token').then((token) => {
console.log('Bearer ' + token);
this.authHeaders = {
headers: new HttpHeaders({
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
})
}
});
}
getInfo(): Observable<Info> {
return this.http.get<Info>(this.authUrl + '/api/users/info', this.authHeaders).pipe(
catchError(this.handleError)
);
}
Run Code Online (Sandbox Code Playgroud)
仪表板
ionViewDidLoad() {
this._dashboardService.getToken();
this._dashboardService.getInfo().subscribe(
info => {
console.log('USER INFO: ' + info);
this.info = info
},
error => {
console.log('INFO ERROR: ' + error);
}
);
}
Run Code Online (Sandbox Code Playgroud) 我有一个在 A2Hosting 共享主机中托管的 socket.io 应用程序,问题是它只使用 xhr 轮询,因为建立套接字握手似乎有错误。
这是我收到的错误:
index.js:83 WebSocket connection to 'wss://www.xxxxxxx.com/socket.io/?
EIO=3&transport=websocket&sid=7KqOx4VgE6xd507zAACf' failed: Error
during WebSocket handshake: Unexpected response code: 400
Run Code Online (Sandbox Code Playgroud)
应用程序.js
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
const port = 65533
app.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin",
"https://www.xxxxx.com/xxxx/xxxx");
res.setHeader("Access-Control-Allow-Credentials", true);
next();
});
server.listen(port, () => console.log(`Example app listening on port
${port}!`));
app.get('/', (req, res) => res.send('Socket is running....'))
// io.set('transports', ['websocket']);
io.on('connection', function (socket) {
socket.on('scan_complete', function (data) {
io.emit("scan_result", data);
console.log(data); …Run Code Online (Sandbox Code Playgroud) 我的 nodejs 应用程序在运行后每隔几周就会不断收到 503 资源超出错误,因此我需要通过 ssh 不断重新启动它。我想知道是否可以安装一些东西,以便在出现错误或崩溃时自动重新启动它。
我在错误期间检查了我们的 A2Hosting 服务器的进程数,但它只是说 0/50。
我正在实时使用推送器。
const express = require("express");
const router = express.Router();
const Pusher = require("pusher");
var pusher = new Pusher({
appId: "xxxxxx",
key: "xxxxxxxxxxxxxxxxxx",
secret: "xxxxxxxxxxxxxxx",
cluster: "ap1",
encrypted: true
});
router.post("/", (req, res) => {
const newVote = {
id: req.body.id,
points: 1
};
pusher.trigger("scan", "scan-player", {
id: req.body.id,
player_id: req.body.player_id,
admin_id: req.body.admin_id
});
return res.json({
success: true,
message: "Scan successful!",
id: req.body.id
});
});
module.exports = router;
Run Code Online (Sandbox Code Playgroud) 我已经读过一些答案,例如解雇当前的ViewController,但是我的情况有所不同,因为我要介绍另一个ViewController。
这段代码向视图控制器提供了其导航控制器,尽管我无法访问它的属性:
@IBAction func didTouchAddFriend(_ sender: UIButton) {
DispatchQueue.main.async {
let storyBoard = UIStoryboard(name: "CustomContact", bundle: nil)
let customContactVC = storyBoard.instantiateViewController(withIdentifier: "CustomContact")
}
}
Run Code Online (Sandbox Code Playgroud)
虽然这不起作用
@IBAction func didTouchAddFriend(_ sender: UIButton) {
DispatchQueue.main.async {
let navigation = UIStoryboard.init(name: "CustomContact", bundle: nil).instantiateInitialViewController() as! UINavigationController
let pickerUserVC = navigation.viewControllers.first as! CustomContactsViewController
self.present(pickerUserVC, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个名为CustomContact.storyboard的故事板,其中包含一个CustomContactsViewController
当我单击didTouchAddFriend时,它仅显示以下错误:
'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <Main.MainViewController: 0x7ff29f06ac00>.'
Run Code Online (Sandbox Code Playgroud)
当我打印pickerUserVC的值时,我无法理解错误cos,它显示了正确的视图控制器:
<Main.CustomContactsViewController: 0x7fd1b7922400>
Run Code Online (Sandbox Code Playgroud)
MainViewController是实现didTouchAddFriend函数的当前视图控制器