Sign in to follow this  
Pedro Alves

can´t make your two or more methods in same route

Recommended Posts

i using nodejs ,mysql ,express
i trying put two methods in same route to render the same file but i have  this error in my firefox 404

my code

     aliança route
     
        const express = require('express')
        const router = express.Router()
        const connection = require('../../Config/database')
        const controllerAdmin = require('../../controllers/Administration')
        const controlleruser = require('../../controllers/Alliances')
       
        router.get('/Administration/Alliances', (req, res) => controllerAdmin.findcidade3(connection, req, res));
        router.get('/Administration/Alliances', (req, res) => controlleruser.findAlianca(connection, req, res));
       
       
        module.exports = app => app.use('/', router)
     
    aliança controller
     
     
        const Allianca = require('../models/Alliances')
       
        const findAlianca = async (connection,  req, res) => {
       
          const allianca = await Allianca.find(connection,req.session.user.username)
          if (!allianca) {
         res.status(404).send('Nenhuma cidade encontrada.')
         return;
        }
        console.log("dddd");
                  req.session.alianca = allianca
                  res.locals.alianca = allianca
        res.render('Administration/Alliances')
          }
       
          module.exports = {
           findAlianca
          }
     
    aliança models
     
        const find = (connection,username) => {
                return new Promise((resolve, reject) => {
                  connection.query(`SELECT alianca.nome,alianca.N_membros,alianca.TAG FROM user INNER JOIN alianca ON user.cod_alianca=alianca.id WHERE user.username='${username}'`, (err, result) => {
                        if(err){
                            reject(err)
                        }else{
                          console.log(result[0]);
                            resolve(result[0])
                        }
                    })
                })
            }
       
            module.exports = {
                find
            }
     
     
    na app tenho  o seguinte
     
        require('./routes/Administration/Alliances')(app)
     
    aliança.jade tenho assim
     
        extends layout
        block title
           .col-xs-6.col-xs-offset-3.col-sm-6.col-sm-offset-3
           .col-sm-4(style='width:76%')
            div.panel.panel-primary(style='height:50px') Alliances Page
            div.panel.panel-primary(style='height:700px')  fdssdklfsdklfjskldfjkldsjfl
              if locals.user.cod_alianca==null
                 p You Dont Have Alliances
              else
                br
                span Your Aliance
                span= locals.alianca.nome
       
           .col-xs-2.panel-red(style='width:24%;height:100%;text-align:center')
         
    coneção com base dados tenho o seguinte
     
        const mysql = require('mysql')
        const config = require( "./config.json" )
        const connection =mysql.createConnection({
         host:config.host,
         user:config.user,
         password:config.password,
         database:config.database,
        // port:config.port
        });
       
        connection.connect((err) =>{
            if(err){
                console.log(err)
                process.exit(0)
            }else{
            console.log('database on')
        }
        })
        connection.query(`CREATE TABLE IF NOT EXISTS user (userId INT(11) NOT NULL AUTO_INCREMENT, username VARCHAR(50) DEFAULT NULL, password VARCHAR(60) DEFAULT NULL, PRIMARY KEY (userId))`, (err ,result) =>{
            if(err){
                console.log(err)
            }
        })
       
        module.exports = connection

and cmd have this errors

 GET /Administration/Alliances 500 217.138 ms - 7876
    GET /Administration/vendor/bootstrap/css/bootstrap.min.css 404 42.201 ms - 7876
    GET /Administration/vendor/fontawesome/css/font-awesome.min.css 404 80.007 ms - 7876
    GET /Administration/vendor/themify-icons/themify-icons.min.css 404 112.356 ms - 7876
    GET /Administration/vendor/animate.css/animate.min.css 404 142.545 ms - 7876
    GET /Administration/vendor/perfect-scrollbar/perfect-scrollbar.min.css 404 176.203 ms - 7876
    GET /Administration/vendor/switchery/switchery.min.css 404 208.608 ms - 7876
    GET /Administration/stylesheets/plugins.css 404 35.953 ms - 7876
    GET /Administration/stylesheets/styles.css 404 64.049 ms - 7876

what i doing wrong

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.