Expressjs の使用中にエラーが発生しました。「/register.html を取得できません」と表示されます。これを解決する方法がわかりません。register.html を /register に表示したいのですが、常にエラーが発生します。ところで、これが私のコードです。このエラーを 1 時間グーグル検索しましたが、まだ機能しません。
app.js
var express = require("express");
var app = express();
var redis = require("redis");
var client = redis.createClient();
var reply;
app.use(express.bodyParser());
client.on("error", function (err) {
console.log("error event - " + client.host + ":" + client.port + " - " + err);
});
app.get("/", function (req, res) {
res.sendfile(__dirname + "/login.html");
});
app.get("/", function (req, res) {
res.sendfile(__dirname + "/register.html");
});
app.post("/login", function (req, res) {
res.sendfile(__dirname + "/login.html");
console.log("--------------------");
console.log(req.body.user.username);
console.log(req.body.user.password);
console.log("--------EOF---------");
client.hmget( "credentials", req.body.user.username, function (err,pass) {
console.log("req.body.username: " + req.body.user.username);
console.log("req.body.password: " + req.body.user.password);
console.log("pass: " + pass );
console.log("err: " + err );
if ( (!err) && pass && pass == req.body.user.password )
res.write( "Successfully logged in!" );
else if ( pass == false)
res.write("Account Does not Exist")
else
res.write( "Password is incorrect");
res.end();
});
});
app.post("/register", function (req, res) {
res.redirect("/register.html");
console.log("--------------------");
console.log(req.body.user.fname);
console.log(req.body.user.lname);
console.log(req.body.user.username);
console.log(req.body.user.pass);
console.log(req.body.user.email);
console.log(req.body.user.mobile);
console.log(req.body.user.mydate);
console.log("--------EOF---------");
client.hmset("credentials",req.body.user.uname, "first_name",req.body.user.fname,
"last_name",req.body.user.lname, "username", req.body.user.uname,
"password", req.body.user.pass, "email", req.body.user.email,
"mobile", req.body.user.mobile, redis.print);
res.write("data inserted");
res.end();
});
app.listen(1337);
ここに私のlogin.htmlがあります
<html>
<head></head>
<body>
<p>
<form method="post" action="/login">
Username: <input type="text" name="user[username]"> <br>
Password: <input type="text" name="user[password]"> <br>
<input type="submit" value="Submit"> <br>
<a href="/register.html">Register!</a>
</form>
</p>
</body>
</html>
これが私のregister.htmlです
<html>
<head></head>
<body>
<p>
<form method="post" action="/register">
First Name: <input type="text" name="user[fname]"> <br>
Last Name: <input type="text" name="user[lname]"> <br>
Username: <input type="text" name="user[username]" > <br>
Password: <input type="text" name="user[password]"> <br>
Email: <input type="text" name="user[email]"> <br>
Mobile Number: <input type="text" name="user[mobile]"> <br>
<input type="submit" value="Submit">
</p>
</form>
</body>
</html>