bmullan91 / express-subdomain

Super simple subdomain middleware for expressjs
414 stars 49 forks source link

subdomain router not work #32

Closed sattha closed 7 years ago

sattha commented 7 years ago

I have define following main domain and sub domain

app.use(subDomain('admin', adminIndexRouter));

app.use('/', indexRouter);
app.use('/login', loginRouter);
app.use('/order', customerOrderRouter);
app.use('/android', androidRouter);
app.use('/finance', financeRouter);
app.use('/packing', packingRouter);
app.use('/admin', adminRouter);
app.use('/report', reportRouter);
app.use('/login', loginRouter);
app.get('/logout', function (req, res) {
    req.logout();
    res.redirect('/');
});

which adminIndexRouter is

var express = require('express');
var path = require('path');
var router = express.Router();

var adminOrderRouter = require(path.join(__dirname, 'adminOrderController'));
var adminBagRouter = require(path.join(__dirname, 'adminBagController'));

/* GET home page. */
router.get('/',
    require('connect-ensure-login').ensureLoggedIn(),
    function (req, res, next) {
        // res.json(req.user);
        res.render('index', {
            slideMenu: {
                user: req.user,
                menus: ["home"]
            },
            user: req.user
        });
    });

router.use('/order', adminOrderRouter);
router.use('/bag', adminBagRouter);

module.exports = router;

for example I access sub-domain from http://admin.app.dev

The problem is I can access main domain form http://admin.app.dev/login or http://admin.app.dev/finance which is not define in sub-domain router context.

sattha commented 7 years ago

duplicate with #27