Я получаю сообщение об ошибке:
throw new TypeError ('Router.use () требуется функция промежуточного программного обеспечения, но получил' + gettype (fn)) v
Я довольно новыйи не уверен, что происходит!Любая помощь будет принята с благодарностью, и дайте мне знать, если есть какая-либо другая информация, которая может быть полезна.Большое спасибо заранее !!!!!!!
Вот мой app.js:
const express = require('express');
const app = express(); // object with methods; One method is router; express creates a server; app allows us to access the server; app.listen hooks up our server;
const morgan = require('morgan'); //app.use(...) morgan says console.log(wht app.use does);
const { db, Review, Toilet, User } = require('./server/db/index');
// Logger:
app.use(morgan('dev')); // implies '/' ('/', morgan('dev'));
//Body parser:
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// public:
app.use(express.static(__dirname + '/public'));
// Backend Routing:
app.use('/api', require('./server/api/index'));
// Setting up server
const PORT = process.env.PORT || 8880;
const syncDb = () => db.sync();
const startListening = () => {
app.listen(PORT, function() {
console.log(
` ***** I'm leisurely listening on pleasant port of ${PORT} *****`
);
});
};
async function bootApp() {
await syncDb();
await startListening();
}
bootApp();
Вот мой сервер / api / index.js:
const router = require('express').Router();
router.use('/toilets', require('./toiletRoutes'));
router.use('/users', require('./userRoutes'));
router.use('/reviews', require('./reviewRoutes'));
module.exports = router;
Вот мой сервер / db / api / ToiletRoutes.js:
const express = require('express');
const router = express.Router();
const { Toilet, User, Review } = require('../db/index');
// Get all toilets
router.get('/', async function(req, res, next) {
console.log('in get all toilets');
try {
const allToilet = await Toilet.findAll();
res.status(200).send(allToilet);
} catch (error) {
next(error);
}
});
module.exports = router;
Вот мой пакет. Json:
{
"name": "newflush",
"version": "1.0.0",
"description": "",
"main": "app.js",
"engines": {
"npm": "6.4.1",
"node": "10.7.0"
},
"scripts": {
"start": "webpack -w & node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-upgrade": "0.0.23",
"express": "^4.16.3",
"google-map-react": "^1.1.2",
"morgan": "^1.9.1",
"path": "^0.12.7",
"pg": "^7.8.1",
"pg-hstore": "^2.3.2",
"react": "^16.5.2",
"react-burger-menu": "^2.5.4",
"react-dom": "^16.5.2",
"react-geocode": "^0.1.2",
"react-google-maps": "^9.4.5",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0",
"sequelize": "^4.43.0",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
}
}
Вот дерево файлов моего сервера