当我点击网址时无法在浏览器中点击路由器

时间:2019-06-07 16:23:17

标签: javascript node.js reactjs express server

  • 我有一个有效的代码库,他们已经在其中设置了节点代理和jwt。
  • 我的服务器在1010端口上运行
  • 但是当我点击此网址]c : - next difference [c : - previous difference do - diff obtain dp - diff put zo - open folded text zc - close folded text :diffupdate - re-scan the files for differences
  • 浏览器屏幕上出现错误http://localhost:1010/sampletest
  • 即使我点击了该网址http://localhost:1010/jump/api/v1,但仍然遇到相同的错误
  • 您能告诉我如何解决它,还是我在配置中缺少任何内容
  • 在下面提供我的index.js和server.js代码

sports.js

Cannot GET /sampletest

index.js

const express = require('express');
const axios = require('axios');
const mime = require('mime-types');

const router = express.Router();
const ResponseUtil = require('../../utils/ResponseUtil');
const AppConstants = require('../../../constants/AppConstants');

const credentials = require('../../../internals/credentials.json');

const memberGroupingHelper = require('../../helpers/rank/memberGrouping');
const exportHelper = require('../../helpers/rank/rankExportHelper');
const formatExportData = require('../../helpers/rank/formatExportData');

const rankCommonHelper = require('../../helpers/rank/rankCommonHelper');
const rankProvDataHelper = require('../../helpers/group/getProvData');

//const aggregateHelper = require('../../helpers/group/aggregateFilter');

const { rankAggregatelastrsApi } = require('jump-svc-utils');


//router.get('/:searchMode/:lastrSearch', (req, res, next) => {
router.get('/sampletest', (req, res, next) => {


  const { originalUrl } = req;

  //console.log(" originalUrl  ", originalUrl);

  const mode = req.params.searchMode;

  const value = encodeURIComponent(req.params.lastrSearch);


  console.log("document 40--->", mode);
  console.log("for document Testing0--->", mode);





  const url = `/jkjkjk/sdjksdjkjksdjksd/sdklsdlksdklsdkl`;

  axios.get(AppConstants.GET_JWT_TOKEN_URL, {
    auth: {
      username: credentials.auth.racfId, password: credentials.auth.password
    }
  })
    .then((jwtResponse) => {
     // var jwtToken = `Bearer ${jwtResponse.data.jwt}`;
            var jwtToken = `Bearer 787878bjhbnmnmmwqdqwqwqwqwqwqwqwqwqwqwqwqwqwqwqwqwqwqw`;


      axios.get(url, { headers: { "Authorization": jwtToken } })

        .then((response) => {
          console.log("document then0--->", response);
          const file = Buffer.from(response.data.content, 'base64');
          const fileType = mime.contentType(response.data.contentInfo.fileType);
          const fileExtension = response.data.contentInfo.fileType.toLowerCase();
          const fileName = `filename=${response.data.contentInfo.id}.${fileExtension}`;
          res.set('Content-Type', fileType);
          res.set('Content-disposition', `attachment; ${fileName}`);
          res.send(file);
        })


        .catch((e) => {
          console.log("e catch document0--->", e);
          console.log("e.message catch document0--->", e.message);

          console.log("catch document--->", e.response);

          if (e.response) {
            return res.status(e.response.status).send(e.response.data);
          }
          res.status(500).send(e.message || 'Something wrong');
        });
    });


  ResponseUtil.callService(res, url);



});

module.exports = router;

1 个答案:

答案 0 :(得分:0)

我没有看到任何呼叫在顶级Express应用程序中注册您的子路由器。您应该需要为每个子路由器调用app.use。