Spaces:
Build error
Build error
File size: 1,540 Bytes
02ec2cc f198f11 2e3927c f198f11 1577403 02ec2cc f198f11 1577403 8c19e68 9bf1940 2e3927c f198f11 2e3927c 02ec2cc 2e3927c 02ec2cc 1577403 f198f11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import 'package:dart_off_server/core.dart' as core;
import 'package:alfred/alfred.dart';
import 'dart:io';
import 'package:openfoodfacts/openfoodfacts.dart';
void main(List<String> arguments) async {
// get port from arguments
var port = 7860;
if (arguments.isEmpty) {
print('Please provide a port number');
} else {
port = int.tryParse(arguments.first) ?? 6565;
}
core.mkConfiguration();
final app = Alfred();
// print line
// print('Starting up server: on port $port');
app.get('/', (req, res) {
res.headers.contentType = ContentType.html;
return '<html><body><h1>Test HTML</h1></body></html>';
});
app.get('/text', (req, res) => 'Text response');
app.get('/json', (req, res) => {'json_response': true});
app.get('/jsonExpressStyle', (req, res) {
res.json({'type': 'traditional_json_response'});
});
app.get('/file', (req, res) => File('test/files/image.jpg'));
app.get('/html', (req, res) {
res.headers.contentType = ContentType.html;
return '<html><body><h1>Test HTML</h1></body></html>';
});
app.post('/post-route', (req, res) async {
final body = await req.body; //JSON body
body != null; //true
});
app.get('/food/search', (req, res) {
final query = req.uri.queryParameters;
return core.search(query).then((value) {
res.json(value);
}).catchError((error) {
res.json(error);
});
});
app.get('/steam', (req, res) {
return core.findTopSteamSellers();
});
await app.listen(port); //Listening on port 6565
}
|