Express js Router无法正常工作

时间:2017-09-17 13:52:04

标签: javascript node.js express routes

我正面临着快递js Routes的困难。我有一个用户路由文件,我在app.js(主文件)中要求。但它总是给出不能GET / auth / register。

我的用户路线如下:

<?php 
namespace classes\server;
use \PDO;

const db_host = "localhost";
const db_name = "dbname";
const db_username = "root";
const db_password = "";

class config
{
    private $connection = null;
    private $db_acct = array("db_access" => ["username" => db_username,
                                             "password" => db_password]);
    private $isConnected = null;
    private $connection_error = null;

    public function __construct()
    {
        try
        {
            $this->connection = new PDO("mysql:host=".db_host.";dbname=".db_name, $this->db_acct["db_access"]["username"], 
                                                                                  $this->db_acct["db_access"]["password"]);
            $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            if($this->connection)
            {
                $this->isConnected = $this->connection;
            }
            else
            {
                $this->isConnected = false;
            }       
        }
        catch(PDOException $x)
        {
            $this->connection_error = $x->getMessage();
        }

    }

    protected function connection()
    {
        return $this->isConnected;
    }

    protected function connection_error()
    {
        return $this->connection_error;
    }
}
 ?>

我的app文件如下:

const express = require('express');
const router  = express.Router();

router.get('register', (req, res, next) => {
    console.log('Hello');
    res.send('Register');
});
module.exports = router;

1 个答案:

答案 0 :(得分:1)

你忘记了符号&#39; /&#39;在您的用户路线中。试试这个:

router.get('/register', (req, res) => {
  console.log('Hello');
  res.send('Register');
});