dart_frog icon indicating copy to clipboard operation
dart_frog copied to clipboard

feat: Serve index.html by default

Open Tienisto opened this issue 3 years ago • 3 comments

Description

I have a single page application written in Vue which gets compiled into public/

I think it is pragmatic to serve index.html in public by default for / if there is no / controller in dart code

Tienisto avatar Dec 13 '22 15:12 Tienisto

Second this. Just found out this package and willing to try it out. Surprised that this isn't a thing. Is there currently any workaround? Worse case is to serve static files separately behind a reverse proxy I guess.

enquestor avatar Dec 13 '22 20:12 enquestor

There is a workaround without a proxy:

https://github.com/VeryGoodOpenSource/dart_frog/issues/90#issuecomment-1244807334

routes/
  - index.dart
import 'dart:io';

import 'package:dart_frog/dart_frog.dart';
import 'package:path/path.dart' as path;

Response onRequest(RequestContext context) {
  final file = File(path.join(Directory.current.path, 'public', 'index.html'));
  if (!file.existsSync()) {
    return Response(body: 'Index Not found');
  }
  final indexHtml = file.readAsStringSync();
  return Response(body: indexHtml, headers: {'Content-Type': 'text/html'});
}

Tienisto avatar Dec 13 '22 21:12 Tienisto

Thanks for the heads-up!

enquestor avatar Dec 14 '22 01:12 enquestor