VeryGoodOpenSource / dart_frog

A fast, minimalistic backend framework for Dart 🎯
https://dartfrog.vgv.dev
MIT License
1.87k stars 150 forks source link

feat: change serving static file directory #309

Closed utamori closed 2 years ago

utamori commented 2 years ago

Description

I would like to distribute Flutter Web apps on Frog. The directory structure should look like this Flutter does not allow you to specify the output path at build time. by moving frontend/build/web to public folder apps can be serve on Frog If we could specify a path other than public in Frog to serve static files, this one step would be eliminated.

├── frontend  // Flutter Web Project
│  ├── build
│    └── web
├── public
├── pubspec.yaml // Frog Server
├── routes

Requirements

Additional Context

There is a package that does the same thing with go server

It would be very useful for certain applications if Frog and Flutter Web could do the same thing!

rel.png (775×254)

https://github.com/shibukawa/frontend-go

//go:build release

package webapp

// ↓this folder is decided by your frontend framework

//go:embed frontend/build/*
var asset embed.FS

init() {
    frontend.SetFrontAsset(asset, frontend.Opt{
        FrameworkType: frontend.NextJS, // select: NextJS, VueJS, SvelteKit, SolidJS
    })
}
felangel commented 2 years ago

Hi @utamori 👋 Thanks for opening an issue!

This can be achieved using a custom entrypoint.

import 'dart:io';

import 'package:dart_frog/dart_frog.dart';

Future<HttpServer> run(Handler handler, InternetAddress ip, int port) {
  final cascade = Cascade()
      .add(createStaticFileHandler(path: 'frontend/build/web'))
      .add(handler);
  return serve(cascade.handler, ip, port);
}

Let me know if that helps 👍

felangel commented 2 years ago

Closing for now since there aren't any actionable next steps. Feel free to comment with any additional questions and I'm happy to continue the conversation 👍

utamori commented 2 years ago

@felangel thanks! It worked fine. It would be helpful if the documentation mentioned how to do this https://dartfrog.vgv.dev/docs/basics/serving-static-files