Route not found
ansarizafar opened this issue · 4 comments
ansarizafar commented
Is there a way to add a handler if there is no matching route and a global handler for error/exception handling?
Is there any plan to support isolates?
deriegle commented
Hi there @ansarizafar!
You can use the following the match any route that doesn't match:
void main() {
var app = express();
app.get('/', (req, res, _) {
res.send('Hello, world');
});
app.all('*', (req, res, next) {
res.send('No route found.');
});
}
No official plans, but I'd love to add that feature in the future and open to anyone contributing to help make that happen!
melWiss commented
can it serve static web pages?
deriegle commented
@melWiss Yes, it can. You can use a few different template engines (Mustache or Jael) or you can use static HTML files.
It will search for HTML files in a top level views
directory by default.
import 'package:dart_express/dart_express.dart';
void main() {
var app = express();
app.get('/', (req, res) {
// This will render an "index.html" located in a "views" directory
// views/index.html
res.render('index');
});
app.listen(3001, (int port) => print('Listening on $port'));
}
melWiss commented
Thanks a lot my friend