Unpub is a self-hosted private Dart Pub server for Enterprise, with a simple web interface to search and view packages information.
pub global activate unpub
unpub --database mongodb://localhost:27017/dart_pub # Replace this with production database uri
Unpub use mongodb as meta information store and file system as package(tarball) store by default.
Dart API is also available for further customization.
import 'package:mongo_dart/mongo_dart.dart';
import 'package:unpub/unpub.dart' as unpub;
main(List<String> args) async {
final db = Db('mongodb://localhost:27017/dart_pub');
await db.open(); // make sure the MongoDB connection opened
final app = unpub.App(
metaStore: unpub.MongoStore(db),
packageStore: unpub.FileStore('./unpub-packages'),
);
final server = await app.serve('0.0.0.0', 4000);
print('Serving at http://${server.address.host}:${server.port}');
}
Option | Description | Default |
---|---|---|
metaStore (Required) |
Meta information store | - |
packageStore (Required) |
Package(tarball) store | - |
upstream |
Upstream url | https://pub.dev |
googleapisProxy |
Http(s) proxy to call googleapis (to get uploader email) | - |
uploadValidator |
See Package validator | - |
Using unpub behind reverse proxy(nginx or another), ensure you have necessary headers
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Workaround for:
# Asynchronous error HttpException:
# Trying to set 'Transfer-Encoding: Chunked' on HTTP 1.0 headers
proxy_http_version 1.1;
Naming conflicts is a common issue for private registry. A reasonable solution is to add prefix to reduce conflict probability.
With uploadValidator
you could check if uploaded package is valid.
var app = unpub.App(
// ...
uploadValidator: (Map<String, dynamic> pubspec, String uploaderEmail) {
// Only allow packages with some specified prefixes to be uploaded
var prefix = 'my_awesome_prefix_';
var name = pubspec['name'] as String;
if (!name.startsWith(prefix)) {
throw 'Package name should starts with $prefix';
}
// Also, you can check if uploader email is valid
if (!uploaderEmail.endsWith('@your-company.com')) {
throw 'Uploader email invalid';
}
}
);
Unpub is designed to be extensible. It is quite easy to customize your own meta store and package store.
import 'package:unpub/unpub.dart' as unpub;
class MyAwesomeMetaStore extends unpub.MetaStore {
// Implement methods of MetaStore abstract class
// ...
}
class MyAwesomePackageStore extends unpub.PackageStore {
// Implement methods of PackageStore abstract class
// ...
}
// Then use it
var app = unpub.App(
metaStore: MyAwesomeMetaStore(),
packageStore: MyAwesomePackageStore(),
);
URL | Badge |
---|---|
/badge/v/{package_name} |
|
/badge/d/{package_name} |
MIT
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。