-
Notifications
You must be signed in to change notification settings - Fork 42
Only first group's routes registered #185
Comments
In fact, only the first lib to be imported is registered. |
You don't need the export. You can simply add the services as sub librarys of my_lib... e.g. library my_lib;
import 'user_service.dart';
import 'api.dart'; user_service.dart: library my_lib.user_service;
import 'package:redstone/redstone.dart';
@Group('/user')
class UserService
{
@Route('/login')
String sayHi() => 'hi';
} api.dart: library my_lib.api;
import 'package:redstone/redstone.dart';
@Group('/api')
class Api
{
@Route('blah')
String blah() => 'blah';
} EDIT: Removed parts example |
The point of this was to avoid parts. And I don't think your first example without parts actually works. It could though. But last time I checked, there was something preventing this from working. It'd only register the first imported library. |
Hmm Ill need to double check, but I thought I have it working with imports. Ill come back to this. Edit: It worked. |
Minimal reproductible code // main.dart
import 'package:redstone/redstone.dart' as app;
import 'package:redstone_sample/rest_api.dart';
main() {
app.redstoneSetUp([#rest_api]);
app.setupConsoleLog();
app.showErrorPage = false;
app.start(port: 8084);
} // lib/rest_api.dart
library rest_api;
import 'group1.dart';
import 'group2.dart'; // lib/group1.dart
import 'package:redstone/redstone.dart' as app;
import 'package:shelf/shelf.dart' as shelf;
@app.Group("/hello1")
class MyGroup {
@app.DefaultRoute()
hello() async {
var a = 12;
return new shelf.Response.ok('hello');
}
@app.Route('/user')
user() => new shelf.Response.ok('user');
} // lib/group2.dart
import 'package:redstone/redstone.dart' as app;
import 'package:shelf/shelf.dart' as shelf;
@app.Group("/hello2")
class MyGroup {
@app.DefaultRoute()
hello() async {
var a = 12;
return new shelf.Response.ok('hello');
}
@app.Route('/user')
user() => new shelf.Response.ok('user');
}
Ignore the "printing twice the same debug info" bug. |
Try this (it works): // lib/rest_api.dart
library rest_api;
import 'group1.dart';
import 'group2.dart'; // lib/group1.dart
library rest_api.group1;
... // lib/group2.dart
library rest_api.group2;
... |
Indeed. @mnordine this could in interest you as a temporary fix. ^ |
Still @indiealexh, this shouldn't be necessary, unless I misunderstand a concept with libraries? |
@Pacane Tbh, I'm not sure how it should work, it just made sense for me to place my "Controllers" or "Services" as sub libraries and just import that at start up. |
That does indeed work, thx for the mention. I don't like the extra step of having to declare a library per-file though. |
Me neither. But it's a step forward removing part/part of if you don't like them. Eventually we might come up with a fix for this though. I'd really like to have one lol |
See https://gitlab.com/mark-nordine/redstone-bug
server.dart:
my_lib.dart:
user_service.dart:
api.dart:
When run, only routes from
user_service.dart
are registered.The text was updated successfully, but these errors were encountered: