i18next / i18next-express-middleware

[deprecated] can be replaced with i18next-http-middleware
https://github.com/i18next/i18next-http-middleware
MIT License
206 stars 52 forks source link

I have error with Object.addRoute apple ? #203

Closed golubvladimir closed 4 years ago

golubvladimir commented 4 years ago

My config

const i18next = require('i18next');
const i18nextMiddleware = require('i18next-express-middleware');
const FilesystemBackend = require('i18next-node-fs-backend');
const { Router } = require('express');

// init middleware for initialization

i18next
  .use(i18nextMiddleware)
  .use(FilesystemBackend)
  .init({
    preload: ['en', 'ru']
  }, function () {
    i18nextMiddleware.addRoute(
      i18next,
      ':lng/test',
      Router,
      'get',
      (req, res) => {
        res.json({status: 'ok'});
      }
    )
  });

const app = express();

app.use(i18nextMiddleware.handle(i18next));

Error:C:...\adminpanel\node_modules\i18next-express-middleware\lib\index.js:185 app[verb || 'get'].apply(app, routes.concat(callbacks)); ^ TypeError: Cannot read property 'apply' of undefined

jamuhl commented 4 years ago

pass in app not Router https://github.com/i18next/i18next-express-middleware#add-localized-routes