Next.js,Express.js应用程序的api正在开发中运行,但生产状态为404

时间:2019-11-04 16:22:46

标签: express nginx next.js production

我已经在生产环境中部署了nextjs,expressjs应用程序,但所有API都得到了404。 我的页面工作正常


  var session = require('express-session');
  var passport = require('passport');
  const KnexSessionStore = require('connect-session-knex')(session);
  const knex  = require('./db/knex.js');
  const authMid = require('./config/utils')


  const app = express();
  app.use(compression())
  app.use(cookieParser());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: false}));

  // sesstion
  const store = new KnexSessionStore({
    knex: knex,
    tablename: 'sessions' // optional. Defaults to 'sessions'
  });

  app.use(session({
    name: 'connect.sid',
    store: store,
    secret: 'somesupersecretkey',
    resave: false,
    saveUninitialized: false,
    cookie: {
        maxAge: 1000 * 60 * 60 * 24 * 7 
    },
    // cookie: { secure: false }
  }));


  app.use(passport.initialize());
  app.use(passport.session());

  require("./config/passport");
  require("./config/passport_fb");
  require("./config/passport_google");
  var routes = require('./routes/index');
  routes.mp_routes(app);

  // Server-side
  const route = pathMatch();


  // pages set up
  // private & public
  app.get('/', (req, res) => {
    return nextApp.render(req, res, '/index', req.query)
  })

  app.get('/questions', (req, res) => {
    return nextApp.render(req, res, '/questions', req.query)
  })

我的route / index.js文件看起来像

module.exports.mp_routes = (app) => {
  app.use('/api/v1', questionsRoutes),
  app.use('/api/v1', answersRoutes)
}

所有nextjs页面和表达api在开发中都能正常工作。我不需要执行任何操作,但是在生产页面上可以正常工作,但是所有api都显示状态404。我该如何解决

0 个答案:

没有答案