📜  版本控制 api nodejs 最佳实践 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:40.132000             🧑  作者: Mango

代码示例1
//version taken out from header

    app.use(function(req, res, next)
    {
       req.version = req.headers['accept-version'];
       console.log(req.version);
       next();
    });

    //version path defined

    app.use('/api', versionRoutes({  
       "1.0.0": respondV1,
       "2.0.0": respondV2
    }));

    function respondV1(req, res, next)
     {   
        app.use('/api',routeV1);
        next();
     }
    function respondV2(req, res, next)
    {
       app.use('/api',routeV2);
       next();
    }*