NodeJS不断加载资源失败:服务器以404(未找到)状态响应

我试图在nmp中运行一个登录项目,我初始化了该项目,然后是数据库端。 现在,当我尝试运行index.html时,出现上述错误。同样,我不确定如何配置项目的“运行配置”。我的代码有什么问题吗?在哪里可以找到有关如何相应配置项目的“运行配置”的更多信息。

var mysql = require('mysql');
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var path = require('path');

var connection = mysql.createConnection({
    host     : 'Host',user     : 'root',password : '',database : 'nodeDB'
});



var app = express();
app.use(session({
    secret: 'secret',resave: true,saveUninitialized: true
}));
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());

app.get('/',function(request,response) {
    response.sendFile(path.join(__dirname + '/index.html'));
});

app.post('/auth',response) {
    var username = request.body.username;
    var password = request.body.password;
    if (username && password) {
        connection.query('SELECT * FROM account WHERE username = ? AND password = ?',[username,password],function(error,results,fields) {
            if (results.length > 0) {
                request.session.loggedin = true;
                request.session.username = username;
                response.redirect('/home');
            } else {
                response.send('Incorrect username and/or Password!');
            }
            response.end();
        });
    } else {
        response.send('Please enter username and Password!');
        response.end();
    }
});

app.get('/home',response) {
    if (request.session.loggedin) {
        response.send('Welcome back,' + request.session.username + '!');
    } else {
        response.send('Please login to view this page!');
    }
    response.end();
});

app.listen(3000);
<script src="/index.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Login Form Tutorial</title>
    <style>
        .login-form {
            width: 300px;
            margin: 0 auto;
            font-family: Tahoma,Geneva,sans-serif;
        }
        .login-form h1 {
            text-align: center;
            color: #4d4d4d;
            font-size: 24px;
            padding: 20px 0 20px 0;
        }
        .login-form input[type="password"],.login-form input[type="text"] {
            width: 100%;
            padding: 15px;
            border: 1px solid #dddddd;
            margin-bottom: 15px;
            box-sizing:border-box;
        }
        .login-form input[type="submit"] {
            width: 100%;
            padding: 15px;
            background-color: #535b63;
            border: 0;
            box-sizing: border-box;
            cursor: pointer;
            font-weight: bold;
            color: #ffffff;
        }
    </style>
</head>
<body>
<div class="login-form">
    <h1>Login Form</h1>
    <form action="auth" method="POST">
        <input type="text" name="username" placeholder="username" required>
        <input type="password" name="password" placeholder="Password" required>
        <input type="submit">
    </form>
</div>
</body>
</html>

NodeJS不断加载资源失败:服务器以404(未找到)状态响应

yuchen886 回答:NodeJS不断加载资源失败:服务器以404(未找到)状态响应

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2632941.html

大家都在问