Giter VIP home page Giter VIP logo

dartserver's Introduction

dart_server

this start a http server for flutter web, it can also proxy api requests for Cross-Origin Request.

Feature

  1. Start a http server at local static directory.
  2. Proxy api requests for Cross-Origin Request.

Run

need install dart sdk,can execute dart command

# install dependence
flutter pub get
# start
dart lib/server.dart

Config

  • Config port, for example:
var server = await http.startServer('127.0.0.1', 3000);
  • Config api proxy, for example:
var pubProxy = Proxy(
    'https://pub.dev',
    publicPath: '',
    timeout: timeout,
  );
  • Config local static directory , for example:
var fs = const LocalFileSystem();
  var vDir = CachingVirtualDirectory(
    app,
    fs,
    allowDirectoryListing: true,
    source: fs.currentDirectory.parent.childDirectory("build").childDirectory("web"),
    maxAge: const Duration(days: 24).inSeconds,
  );

中文:

dart_server

为flutter web启动一个http服务器,并且可以代理api请求,解决跨域请求问题。

功能

  1. 为本地文件夹启动一个http服务,例如为flutter web的产物启动http服务
  2. 通过接口代理 解决flutter web调用接口时跨域问题

执行

需要安装dart sdk,可以运行dart命令

# 安装依赖
flutter pub get
# 启动服务
dart lib/server.dart

配置

  • 配置端口号, 例如:
var server = await http.startServer('127.0.0.1', 3000);
  • 配置接口代理, 例如:
var pubProxy = Proxy(
    'https://pub.dev',
    publicPath: '',
    timeout: timeout,
  );
  • 配置本地文件夹地址 , 例如:
var fs = const LocalFileSystem();
  var vDir = CachingVirtualDirectory(
    app,
    fs,
    allowDirectoryListing: true,
    source: fs.currentDirectory.parent.childDirectory("build").childDirectory("web"),
    maxAge: const Duration(days: 24).inSeconds,
  );

Contact me:

License

Copyright 2019 MasonLiu, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

dartserver's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.