platform/packages/jinja/example/main.dart

38 lines
986 B
Dart
Raw Normal View History

2019-01-29 18:06:58 +00:00
import 'dart:io';
2021-06-26 10:34:23 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_jinja/angel3_jinja.dart';
2019-01-29 18:06:58 +00:00
import 'package:path/path.dart' as p;
2021-06-20 12:37:20 +00:00
void main() async {
var app = Protevus();
var http = ProtevusHttp(app);
2019-01-29 18:06:58 +00:00
var viewsDir = p.join(
p.dirname(
p.fromUri(Platform.script),
),
'views',
);
// Enable Jinja2 views
await app.configure(jinja(path: viewsDir));
// Add routes.
// See: https://github.com/ykmnkmi/jinja.dart/blob/master/example/bin/server.dart
app
..get('/', (req, res) => res.render('index.html'))
..get('/hello', (req, res) => res.render('hello.html', {'name': 'user'}))
..get('/hello/:name', (req, res) => res.render('hello.html', req.params));
app.fallback((req, res) {
res
..statusCode = 404
..write('404 Not Found :(');
});
// Start the server
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}