新手 FeathersJS 用户在这里。我显然缺少一些关键的理解。
我正在尝试使用 MySQL 模型创建一个简单的 REST API。我正在尝试遵循此问题线程中文档引用的代码结构。我在初始app.use()
块工作中定义的路线,但不是在它之后定义的路线。部分代码在这里,休息在这个要点
const app = feathers();
app.configure(configuration(path.join(__dirname, '..')));
app.use(compress())
.options('*', cors())
.use(cors())
.use(favicon(path.join(app.get('public'), 'favicon.ico')))
/* THIS ROUTE WORKS FINE */
.use('/', serveStatic(app.get('public')))
.use(bodyParser.json())
.use(bodyParser.urlencoded({
extended: true
}))
.configure(hooks())
.configure(rest())
.configure(socketio())
.configure(models)
.configure(services)
.configure(middleware);
const appModels = app.get('models');
const beerOptions = {
Model: appModels.beer,
paginate: {
default: 15,
max: 50
}
};
/* NEITHER OF THESE ROUTES WORK */
app.use('/beer', service(beerOptions));
// IF YOU DELETE THE DEFINITION ABOVE AND UNCOMMENT
// THIS NEXT LINE, THE ROOT URL GIVES A 404
// app.use('/', serveStatic(app.get('public')));
应用程序时我没有收到任何错误npm start
。但是,我的/beer
路线和那里定义的任何路线一样只有 404 秒。我已经通过指南寻找我误解的根源。但我有点卡住了。