簡體   English   中英

為什么在我的 namecheap nodejs 應用程序中訪問被拒絕?

[英]Why am I getting Access denied in my namecheap nodejs app?

我使用 NodeJS、Express 和 MariaDB 創建了一個簡單的 API,以測試我遇到的數據庫連接問題。 這在本地工作正常,但在 NameCheap 服務器上卻不行。 這是我得到的錯誤:

(conn=18541114, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)

錯誤日志:

    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2798261) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:2798261) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2806739) UnhandledPromiseRejectionWarning: Error: (conn=17370601, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2806739) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:2806739) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2807107) UnhandledPromiseRejectionWarning: Error: (conn=17370830, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2807107) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:2807107) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2813149) UnhandledPromiseRejectionWarning: Error: (conn=17375021, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2813149) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:2813149) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2817491) UnhandledPromiseRejectionWarning: Error: (conn=17377684, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2817491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:2817491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:3226965) UnhandledPromiseRejectionWarning: Error: (conn=17531002, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:3226965) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:3226965) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

這是我的簡單 server.js:

const express = require('express');
const dotenv = require('dotenv');

dotenv.config({path: '.env-local'});

const PORT = process.env.PORT || '3000';
const app = express();

const userRouter = require('./routes/user');


app.use(express.json());
app.use(express.urlencoded({extended:false}));

//routes
app.get('/', (req, res) => {
    res.status(200).send("this is not why you're here. Go to /user/:id and replace :id with your user id.");
});

//middleware
app.use('/user', userRouter);

//start listening
/*
app.listen(PORT, () => {
    console.log(`Listening on port ${PORT}`);
});
*/
app.listen();

用戶.js

const express = require('express');
const router = express.Router();
const pool = require('../helpers/database');
const bcrypt = require('bcrypt');

router.get('/:id', async (req, res) => {
    try {
        const sqlQuery = 'SELECT id, email, password, created_at FROM user WHERE id=?';
        const rows = await pool.query(sqlQuery, req.params.id);
        res.status(200).json(rows);
    } catch (error) {
        res.status(400).send(error.message);
    }
    //res.status(200).json({id:req.params.id});
})

router.post('/register', async (req,res) => {
    try {
        const {email, password} = req.body;

        const encryptedPassword = await bcrypt.hash(password, 10);

        const sqlQuery = 'INSERT INTO user (email, password) VALUES (?,?)';
        const result = await pool.query(sqlQuery, [email, encryptedPassword]);

        res.status(200).json({userId: result.insertId});
    } catch (error) {
        res.status(400).send(error.message);
    }
});

module.exports = router;

數據庫.js:

const mariadb = require('mariadb');

const pool = mariadb.createPool({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
    connectionLimit: 5
})

//connect/check for errors
pool.getConnection((err, connection) => {
    if(err) {
        if (err.code === 'PROTOCOL_CONNECTION_LOST') {
            console.error('Database connection lost');
        }
        if (err.code === 'ER_CON_COUNT_ERROR') {
            console.error('Database has too many connection');
        }
        if (err.code === 'ECONNREFUSED') {
            console.error('Database connection was refused');
        }
    }
    console.log('yes connected!!: ', connection);
    if (connection) connection.release();

    return;
});

module.exports = pool;

我也設置了 Namecheap 環境變量:

#PORT=3000
DB_HOST= localhost
DB_USER= madejnsw_demouser
DB_PASS= A(uGZY$Psx81
DB_NAME= madejnsw_demo_user

用戶也擁有所有權限,我無法用 Namecheap 解決這個問題,有人成功地在 namecheap 服務器上啟動了一個帶有 mariadb 數據庫的工作 nodejs 應用程序嗎? 我將不勝感激這里的任何幫助。 謝謝。

我使用 Namecheap PhpMyAdmin 重新創建了數據庫,並且支持人員必須最終解決一些終端問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM