项目链接
https://github.com/Kammikazy/project
我无法在同一条路线上获得两种或两种以上的方法
我有代码404
我使用mysql nodejs并表达
我的代码
管制者联盟
const User = require('../models/Alliances')
const findAlianca = async (connection, req, res) => {
const Allianca = await User.find(connection, req.session.user.username)
if (!Allianca) {
res.status(404).send('Nenhuma cidade encontrada.');
return;
}
console.log("dddd");
req.session.Allianca = Allianca
res.locals.Allianca = Allianca
res.render('Administration/Alliances')
}
module.exports = {
findAlianca
}
路线联盟
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/limitado', (req, res) => controlleruser.findAlianca(connection, req, res))
module.exports = app => app.use('/', router)
模型联盟
const find =(connection,username)=> {
返回新的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}'
,(错误,结果)=> {如果(错误){
拒绝(错误)
}其他{
解决(结果)
}
})
})
}
module.exports = {
find
}
翡翠联盟
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.Allianca.nome
.col-xs-2.panel-red(style='width:24%;height:100%;text-align:center')
我的应用
require('./routes/Administration/Alliances')(app)
我的连接数据库
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')
}
})
我做错了什么我找不到解决方案
最佳答案
不确定您要问什么,但是,如果要在同一路由/ API中调用多个函数,可以执行以下操作:
使用expressJs可以使用next
函数,例如:
app.get('/Administration/Alliances', (req, res, next) => {
//Do something here and to add data to your request use
req.body.newData = 'newData';
//after this just call next function
next();
}, (req, res, next) => {
//Can continue this cycle of calling next function until last `sendResponse` function is reached.
//Can even set `error` in request for `sendResponse`
req.error = "Some error";
next();
}, (req, res) => {
if(req.error) {
res.status(400).send(req.error);
} else {
res.status(200).send(req.body.result);
}
});