Dart服务器:终端在使用dart run后总是返回Killed

1tuwyuhd  于 2023-05-11  发布在  其他
关注(0)|答案(1)|浏览(105)

这个dart服务器项目在我的电脑上运行时工作成功。但当我在服务器上运行时,我得到了这个。

服务器是Ubuntu 20.04 (LTS) x64。我用这个代码试了一下:

import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_router/shelf_router.dart' as shelf_router;
import 'package:shelf_static/shelf_static.dart' as shelf_static;

Future main(List<String> arguments) async {
  final cascade = Cascade().add(_staticHandler).add(_router);
  final server = await shelf_io.serve(cascade.handler, InternetAddress.anyIPv4, 8085);
  print('\nServer is running\naddress:${server.address.address}\nhost:${server.address.host}\nport: ${server.port}\n');
}


final _staticHandler = shelf_static.createStaticHandler('public_folder', defaultDocument: 'index.html');
final _router = shelf_router.Router()
  ..all('/<ignored|.*>', (Request request) {
    return Response.internalServerError();
  });

依赖关系:

dependencies:
  path: ^1.8.0
  html: ^0.15.1
  http_parser: ^4.0.2
  shelf: ^1.4.0
  shelf_router: ^1.1.3
  shelf_multipart: ^1.0.0
  shelf_static: ^1.1.1
  mongo_dart: ^0.9.1
  mime: ^1.0.2
  mailer: ^6.0.0
  synchronized: ^3.0.1
  pdf: ^3.10.1

我按照下面的https://dart.dev/get-dart安装Dart SDK

sudo apt update
sudo apt install apt-transport-https
wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
sudo apt update
sudo apt install dart

dart --version
Dart SDK version: 2.19.6 (stable) (Unknown timestamp) on "linux_x64"

如果我用一个基本的代码

void main(){
  print('main');
}

发生了什么?

6jjcrrmo

6jjcrrmo1#

在我将内存从0. 5 GB增加到1 GB后,它才能工作。但我想知道为什么像这样的基本代码会占用这么多内存。这是一个新的服务器,只需安装NGINX,MongoDB和Dart SDK。很奇怪

相关问题