예제 #1
0
    def handle(self):
        # Check for the 2.0 patch.
        self._check_patch()

        if self.option('reload'):
            logger = DefaultLogger(LogLevel.INFO)

            # worker args are pickled and then passed to the new process
            worker_args = [
                self.option("host"),
                self.option("port"),
                "wsgi:application",
            ]

            reloader = Reloader(
                "masonite.commands._devserver.run",
                find_default_monitor_factory(logger),
                logger,
                worker_args=worker_args,
            )

            self._run_reloader(reloader, extra_files=[".env"])

        else:
            from wsgi import application
            from ._devserver import run
            run(self.option("host"), self.option("port"), application)
예제 #2
0
    def handle(self):
        if has_unmigrated_migrations():
            self.comment("\nYou have unmigrated migrations. Run 'craft migrate' to migrate them\n")

        if not self.option('dont-reload'):
            logger = DefaultLogger(LogLevel.INFO)

            # worker args are pickled and then passed to the new process
            worker_args = [
                self.option("host"), self.option("port"), "wsgi:application",
            ]

            reloader = Reloader(
                "masonite.commands._devserver.run",
                find_default_monitor_factory(logger),
                logger,
                worker_args=worker_args,
            )

            self._run_reloader(reloader, extra_files=[".env", "storage/"])

        else:
            from wsgi import application
            from ._devserver import run
            run(self.option("host"), self.option("port"), application)
예제 #3
0
    def handle(self):
        if has_unmigrated_migrations():
            self.comment(
                "\nYou have unmigrated migrations. Run 'craft migrate' to migrate them\n"
            )

        if self.option('live-reload'):
            try:
                from livereload import Server
            except ImportError:
                raise DriverLibraryNotFound(
                    "Could not find the livereload library. Install it by running 'pip install livereload==2.5.1'"
                )

            from wsgi import container
            from config import application
            import glob

            server = Server(container.make('WSGI'))
            for filepath in glob.glob('resources/templates/**/*/'):
                server.watch(filepath)

            self.line('')
            self.info('Live reload server is starting...')
            self.info(
                'This will only work for templates. Changes to Python files may require a browser refresh.'
            )
            self.line('')
            application = server.serve(
                port=self.option('port'),
                restart_delay=self.option('reload-interval'),
                liveport=5500,
                root=application.BASE_DIRECTORY,
                debug=True)
            return

        if not self.option('dont-reload'):
            logger = DefaultLogger(LogLevel.INFO)

            # worker args are pickled and then passed to the new process
            worker_args = [
                self.option("host"),
                self.option("port"),
                "wsgi:application",
            ]

            reloader = Reloader(
                "masonite.commands._devserver.run",
                find_default_monitor_factory(logger),
                logger,
                worker_args=worker_args,
            )

            self._run_reloader(reloader, extra_files=[".env", "storage/"])

        else:
            from wsgi import application
            from ._devserver import run
            run(self.option("host"), self.option("port"), application)