表达式子域处理程序路由混淆了

时间:2016-03-15 11:34:07

标签: node.js express subdomain

我试图让我的子域名在快递中与每个不同的路由器一起工作但是它们混淆了。

当我要访问panel.localhost:3333 / login时,我会看到登录页面。但无论何时我去api.localhost:3333 / login,我都会得到相同的页面...而且我没有在de api路由器中定义登录路由。那么有谁知道如何解决这个问题? :)

import { renderer, listen, sessionConfiguration } from './server.express';
import { _static, scripts, modules, staticPages } from './server.static';
import { serverRegisterAPIs } from './server.apis';
import serverConfiguration from './server.configuration';

let express = require('express'),
    app = express(),
    mongoose = require('mongoose'),
    routerPanel = express.Router(),
    routerApi = express.Router();

serverConfiguration(app).then(function(configuration) {

    mongoose.connect(process.configuration.mongo.url);

    app.use( require('express-subdomain-handler')({ baseUrl: 'localhost', prefix: 'subdomain', logger: true }) );

    // configure the session to ....
    sessionConfiguration(app);
    // configure the renderer
    renderer(app);

    // hook up a few static calls to the server
    _static(routerPanel, express);
    scripts(routerPanel, express);
    modules(routerPanel, express);
    // register static files
    staticPages(routerPanel);

    // register api
    //serverRegisterAPIs(routerApi);


    routerApi.get('/', (req, res)=>{
        console.log("test");
    });
    //set subdomains
    app.use('/subdomain/:panel',routerPanel);
    app.use('/subdomain/:api', routerApi);

    // start listening
    listen(app);
});

1 个答案:

答案 0 :(得分:0)

在我设置子域名的地方,我已在路由中添加:,以便其参数express将进行解析。所以我删除了:,现在它正在工作!