各位大神,才学node,请问我该如何做才能让我网站的所有路由都是基于localhost:port/kkk这种形式的? 比如登录时localhost:port/kkk/login,注册时localhost:port/kkk/register。难道要每个路由前面都手动添加一个/kkk/么? 谢谢大家~
不是 例:
//app.js var app = express(); var user = require("user"); user("/kkk",app);
//user.js module.exports = function(app) { app.post("/login",function(req,res){ }); }
https://github.com/moajs/mount-routes
@gjc9620 谢谢了,还有一个问题,比如我有A和B两个管理员,A的网址设定为localhost:port/a,B的网址设定为localhost:port/b,他们的登录页面分别为localhost:port/a/login和localhost:port/b/login,像这种多种的相对路径如何设置呀?
看这个express-router
http://expressjs.com/en/guide/routing.html#express-router
@zhengyue770
app.get("/:user/login",function(req, res){ req.params.user //这里就能拿到那个user是谁了 })
@zhengyue770 为啥要有不同的登录地址?如果不在一个数据库为什么不考虑分开部署呢
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
不是 例:
https://github.com/moajs/mount-routes
@gjc9620 谢谢了,还有一个问题,比如我有A和B两个管理员,A的网址设定为localhost:port/a,B的网址设定为localhost:port/b,他们的登录页面分别为localhost:port/a/login和localhost:port/b/login,像这种多种的相对路径如何设置呀?
看这个express-router
http://expressjs.com/en/guide/routing.html#express-router
@zhengyue770
@zhengyue770 为啥要有不同的登录地址?如果不在一个数据库为什么不考虑分开部署呢