Run the ArchiveBox HTTP server
(runserver_args: Optional[List[str]]=None,
reload: bool=False,
debug: bool=False,
init: bool=False,
quick_init: bool=False,
createsuperuser: bool=False,
out_dir: Path=OUTPUT_DIR)
| 1291 | |
| 1292 | @enforce_types |
| 1293 | def server(runserver_args: Optional[List[str]]=None, |
| 1294 | reload: bool=False, |
| 1295 | debug: bool=False, |
| 1296 | init: bool=False, |
| 1297 | quick_init: bool=False, |
| 1298 | createsuperuser: bool=False, |
| 1299 | out_dir: Path=OUTPUT_DIR) -> None: |
| 1300 | """Run the ArchiveBox HTTP server""" |
| 1301 | |
| 1302 | runserver_args = runserver_args or [] |
| 1303 | |
| 1304 | if init: |
| 1305 | run_subcommand('init', stdin=None, pwd=out_dir) |
| 1306 | print() |
| 1307 | elif quick_init: |
| 1308 | run_subcommand('init', subcommand_args=['--quick'], stdin=None, pwd=out_dir) |
| 1309 | print() |
| 1310 | |
| 1311 | if createsuperuser: |
| 1312 | run_subcommand('manage', subcommand_args=['createsuperuser'], pwd=out_dir) |
| 1313 | print() |
| 1314 | |
| 1315 | # setup config for django runserver |
| 1316 | from . import config |
| 1317 | config.SHOW_PROGRESS = False |
| 1318 | config.DEBUG = config.DEBUG or debug |
| 1319 | |
| 1320 | check_data_folder(out_dir=out_dir) |
| 1321 | |
| 1322 | from django.core.management import call_command |
| 1323 | from django.contrib.auth.models import User |
| 1324 | |
| 1325 | print('{green}[+] Starting ArchiveBox webserver...{reset}'.format(**ANSI)) |
| 1326 | print(' > Logging errors to ./logs/errors.log') |
| 1327 | if not User.objects.filter(is_superuser=True).exists(): |
| 1328 | print('{lightyellow}[!] No admin users exist yet, you will not be able to edit links in the UI.{reset}'.format(**ANSI)) |
| 1329 | print() |
| 1330 | print(' To create an admin user, run:') |
| 1331 | print(' archivebox manage createsuperuser') |
| 1332 | print() |
| 1333 | |
| 1334 | # fallback to serving staticfiles insecurely with django when DEBUG=False |
| 1335 | if not config.DEBUG: |
| 1336 | runserver_args.append('--insecure') # TODO: serve statics w/ nginx instead |
| 1337 | |
| 1338 | # toggle autoreloading when archivebox code changes (it's on by default) |
| 1339 | if not reload: |
| 1340 | runserver_args.append('--noreload') |
| 1341 | |
| 1342 | config.SHOW_PROGRESS = False |
| 1343 | config.DEBUG = config.DEBUG or debug |
| 1344 | |
| 1345 | call_command("runserver", *runserver_args) |
| 1346 | |
| 1347 | |
| 1348 | @enforce_types |
no test coverage detected