unpub_next
Note
Fork Notice: unpub_next is an actively maintained fork of pd4d10/unpub (which was no longer actively maintained).
All dependencies have been updated to modern versions and the codebase has been modernized to leverage Dart 3 features.
unpub_next is a self-hosted private Dart Pub server for Enterprise, with a simple web interface to search and view packages information.
Screenshots

Usage
Docker & Docker Compose (Recommended for local / production)
You can run unpub_next alongside a MongoDB container with a single command:
docker compose up -d
Access the server and web UI at: http://localhost:4000.
The container includes a built-in TCP wait mechanism powered by docker-compose-wait (similar to trevorwang/docker-unpub), ensuring MongoDB is actively accepting connections before unpub_next launches.
Tip
For in-depth Docker documentation, wait mechanism configuration, data volumes, and the complete environment variables reference, see docker/README.md.
Environment Variables Summary
You can configure the deployment via environment variables or a .env file (see .env.example):
| Variable | Description | Default |
|---|---|---|
MONGO_URL / MONGODB_URI / DB_URL |
Full MongoDB connection URI | - |
MONGO_HOST |
MongoDB hostname | mongo (or localhost) |
MONGO_PORT |
MongoDB port | 27017 |
MONGO_DB |
MongoDB database name | dart_pub |
MONGO_USER |
MongoDB username (optional) | admin |
MONGO_PASSWORD |
MongoDB password (optional) | secretpassword |
MONGO_AUTH_SOURCE |
MongoDB auth source database | admin |
WAIT_HOSTS |
Host:port pairs to wait for before starting | Inferred from MongoDB host/port |
OVERRIDE_UPLOADER_EMAIL |
Override uploader email for published packages | - |
UNPUB_PORT |
Port to expose | 4000 |
UNPUB_HOST |
Host address to bind | 0.0.0.0 |
UNPUB_PROXY_ORIGIN |
Public base URL (for reverse proxies) | http://localhost:4000 |
UNPUB_DATA_DIR |
Directory for tarball packages storage | /app/data |
Dockerfile
Build and run the standalone container directly from the repository root:
docker build -f docker/Dockerfile -t unpub_next .
docker run -d -p 4000:4000 \
-e MONGO_URL="mongodb://host.docker.internal:27017/dart_pub" \
-e WAIT_HOSTS="host.docker.internal:27017" \
-e OVERRIDE_UPLOADER_EMAIL="admin@example.com" \
-v unpub_data:/app/data \
unpub_next
Command Line
dart pub global activate unpub_next
unpub_next --database mongodb://localhost:27017/dart_pub # Replace this with production database uri
The command
unpubis also available as an alias for backwards compatibility.
Options:
--help: Print CLI usage options.-h, --host: Host to bind to (default:0.0.0.0).-p, --port: Port to listen on (default:4000).-d, --database: MongoDB connection URI (default:mongodb://localhost:27017/dart_puborMONGO_URL).-o, --proxy-origin: Base URL if served behind a reverse proxy.-e, --override-uploader-email: Override the uploader email address for published packages.
unpub_next uses MongoDB as meta information store and the file system as package (tarball) store by default.
Dart API is also available for further customization.
Dart API
import 'package:mongo_dart/mongo_dart.dart';
import 'package:unpub_next/unpub_next.dart' as unpub;
Future<void> 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}');
}
Options
| 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) | - |
overrideUploaderEmail |
Override uploader email address | - |
uploadValidator |
See Package validator | - |
Usage behind reverse-proxy
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;
Package validator
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';
}
}
);
Customize meta and package store
unpub_next is designed to be extensible. It is quite easy to customize your own meta store and package store.
import 'package:unpub_next/unpub_next.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(),
);
Available Package Stores
- unpub_next_aws: AWS S3 package store.
Alternatives
- pub-dev: Source code of pub.dev, which should be deployed at Google Cloud Platform.
- pub_server: An alpha version of pub server provided by Dart team.
Credits
- pd4d10/unpub: Original unpub project.
- pub-dev: Web page styles are mostly imported from https://pub.dev directly.
- shields: Badges generation.
License
MIT