我有一个类似于这个的设置:
var WebSocketServer = require("ws").Server,
express = require("express"),
http = require("http"),
app = express(),
server = http.createServer(app);
app.post("/login", login);
app.get("/...", callSomething);
// ...
server.listen(8000);
var wss = new WebSocketServer({server: server});
wss.on("connection", function(ws){
// ...
});
Run Code Online (Sandbox Code Playgroud)
我想将WebSocketServer放在特定路径下,例如可能"...com/whatever".问题是如何设置路径?可能吗?
我有点困惑.有人可以向我解释这两种反应状态之间的区别是什么:
HTTP/1.1 101 Web Socket Protocol Handshake
HTTP/1.1 101 Switching Protocols
Run Code Online (Sandbox Code Playgroud)
我得到的回应是否重要?
我已经阅读了几篇关于这个问题的文章,但是他们都没有帮助我,我有点困惑该做什么.
基本上,我想检查sql查询是否执行没有任何错误.为此,我是否必须使用if下面显示的两个语句?
if($stmt = $mysqli->prepare("INSERT INTO table VALUES (?, ?, ?);"))
{
$stmt->bind_param("sss", $a, $b, $c);
if(!$stmt->execute())
{
// Do I have to catch the problem here?
}
if($stmt->affected_rows === -1){
// Do I have to catch the problem here?
}
$stmt->close();
}
else
{
// Do I need to catch the problem here?
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的正则表达式,它应该匹配由字母(0-5)组成的单词,但它似乎不起作用.正则表达式应该如何在ExpressJS中使用?我试图验证的URL可能看起来像something.com/abcd
var express = require("express"),
app = express();
app.get("/:id(^[a-z]{0,5}$)", function(req, res) {
res.send("The right path!");
});
app.listen(8000);
Run Code Online (Sandbox Code Playgroud) express ×2
javascript ×2
node.js ×2
websocket ×2
database ×1
http ×1
http-headers ×1
mysqli ×1
php ×1
regex ×1