Updated readme with instructions
This commit is contained in:
@@ -4,7 +4,7 @@ enum Status { ok, error }
|
||||
|
||||
class ShrinkRay {
|
||||
static const shrinkLength = 6;
|
||||
static const String shrinkChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._';
|
||||
static const String shrinkChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
|
||||
static ({Status status, String content}) shrinkUrl(String urlStr) {
|
||||
try {
|
||||
|
||||
@@ -21,7 +21,6 @@ Future<Response> onRequest(RequestContext context) async {
|
||||
if (url == null) {
|
||||
return Response(statusCode: 401, body: 'Missing url');
|
||||
}
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
final res = ShrinkRay.shrinkUrl(url);
|
||||
switch (res.status) {
|
||||
case Status.ok:
|
||||
@@ -40,6 +39,13 @@ Future<Response> onRequest(RequestContext context) async {
|
||||
return Response(statusCode: 500, body: 'Unexpected error occurred');
|
||||
}
|
||||
case HttpMethod.get:
|
||||
// final maybeUrl = shrunkUrls[urlPath];
|
||||
// switch (maybeUrl) {
|
||||
// case null:
|
||||
// return Response(statusCode: 404);
|
||||
// default:
|
||||
// return Response(statusCode: 308, headers: {'Location': maybeUrl});
|
||||
// }
|
||||
final file = File(path.join(Directory.current.path, 'public', 'index.html'));
|
||||
if (!file.existsSync()) {
|
||||
return Response(body: 'Index Not found');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dart_frog/dart_frog.dart';
|
||||
import 'package:new_backend/shrink_ray.dart';
|
||||
|
||||
@@ -18,7 +16,7 @@ Future<Response> onRequest(RequestContext context, String urlPath) async {
|
||||
case null:
|
||||
return Response(statusCode: 404);
|
||||
default:
|
||||
return Response(statusCode: 302, headers: {'Location': maybeUrl});
|
||||
return Response(statusCode: 308, headers: {'Location': maybeUrl});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,6 @@ class _MockRequestContext extends Mock implements RequestContext {}
|
||||
|
||||
void main() {
|
||||
group('GET /', () {
|
||||
test('responds with a 200 and "Welcome to Dart Frog!".', () {
|
||||
// final context = _MockRequestContext();
|
||||
// final response = route.onRequest(context);
|
||||
// expect(response.statusCode, equals(HttpStatus.ok));
|
||||
// expect(
|
||||
// response.body(),
|
||||
// completion(equals('Welcome to Dart Frog!')),
|
||||
// );
|
||||
});
|
||||
test('responds with a 200 and "Welcome to Dart Frog!".', () {});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user