businessCheck.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const { verify } = require('jsonwebtoken');
  2. const { isProd, jwtSecretBusin } = require('../config');
  3. const { onError } = require('../utils');
  4. module.exports = () => {
  5. return (req, res, next) => {
  6. if (/^\/(login)?\/?$/.test(req.path)) {
  7. return next();
  8. }
  9. // console.log(req.originalUrl);
  10. // const { token } = req.cookies;
  11. // // console.log(req.headers);
  12. // // console.log(token);
  13. // if (token) {
  14. // req.admin = verify(token, jwtSecretAdmin);
  15. // // console.log(req.user);
  16. // return next();
  17. // }
  18. if (req.path.includes('phone_login')) {
  19. return next();
  20. }
  21. if (req.path.includes('sms')) {
  22. return next();
  23. }
  24. console.log(req.path);
  25. if (req.path === '/clue/home') {
  26. return next();
  27. }
  28. if (req.path.includes('problem')) {
  29. return next();
  30. }
  31. console.log(1);
  32. console.log(req.session);
  33. console.log(req);
  34. console.log(req.headers);
  35. const bus = req.session.business;
  36. if (bus) {
  37. req.business = bus;
  38. console.log(3);
  39. return next();
  40. }
  41. // if (!isProd() && !req.business && !req.hostname.includes('fuxicarbon')) {
  42. if (!isProd() && !req.business) {
  43. console.log(2);
  44. req.business = {
  45. id: 10000,
  46. };
  47. return next();
  48. }
  49. return res.send(onError('用户错误'));
  50. };
  51. };