-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let nikola serve work together with non-root BASE_URL or SITE_URL.
- Loading branch information
1 parent
168d9cd
commit c94983e
Showing
9 changed files
with
276 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import urllib | ||
|
||
|
||
def base_path_from_siteuri(siteuri: str) -> str: | ||
"""Extract the path part from a URI such as site['SITE_URL']. | ||
The path never ends with a "/". (If only "/" is intended, it is empty.) | ||
""" | ||
path = urllib.parse.urlsplit(siteuri).path | ||
if path.endswith("/"): | ||
path = path[:-1] | ||
return path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pathlib | ||
import socket | ||
from typing import Dict, Any | ||
|
||
from ..helper import FakeSite | ||
from nikola.utils import get_logger | ||
|
||
SERVER_ADDRESS = "localhost" | ||
TEST_MAX_DURATION = 10 # Watchdog: Give up the test if it did not succeed during this time span. | ||
|
||
# Folder that has the fixture file we expect the server to serve: | ||
OUTPUT_FOLDER = pathlib.Path(__file__).parent.parent / "data" / "dev_server_sample_output_folder" | ||
|
||
LOGGER = get_logger("test_dev_server") | ||
|
||
|
||
def find_unused_port() -> int: | ||
"""Ask the OS for a currently unused port number. | ||
(More precisely, a port that can be used for a TCP server servicing SERVER_ADDRESS.) | ||
We use a method here rather than a fixture to minimize side effects of failing tests. | ||
""" | ||
s = socket.socket() | ||
try: | ||
ANY_PORT = 0 | ||
s.bind((SERVER_ADDRESS, ANY_PORT)) | ||
address, port = s.getsockname() | ||
LOGGER.info("Trying to set up dev server on http://%s:%i/", address, port) | ||
return port | ||
finally: | ||
s.close() | ||
|
||
|
||
class MyFakeSite(FakeSite): | ||
def __init__(self, config: Dict[str, Any], configuration_filename="conf.py"): | ||
super(MyFakeSite, self).__init__() | ||
self.configured = True | ||
self.debug = True | ||
self.THEMES = [] | ||
self._plugin_places = [] | ||
self.registered_auto_watched_folders = set() | ||
self.config = config | ||
self.configuration_filename = configuration_filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.