-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let nikola serve work together with non-root BASE_URL or SITE_URL. Fixes #3726 #3804
Open
aknrdureegaesr
wants to merge
5
commits into
getnikola:master
Choose a base branch
from
aknrdureegaesr:serve-non-root-site
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
81320b0
Let nikola serve work together with non-root BASE_URL or SITE_URL.
aknrdureegaesr 85f2755
Backporting a type hint to Python 3.8.
aknrdureegaesr 22f16d2
pydocstyle improvement.
aknrdureegaesr 44a66cc
Comment cosmetics.
aknrdureegaesr 9a88a2d
Workaround for Windows \r\n newlines.
aknrdureegaesr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 @@ | ||
"""Extracting the base path from site['SITE_URL'] or site['BASE_URL'].""" | ||
|
||
import urllib | ||
|
||
|
||
def base_path_from_siteuri(siteuri: str) -> str: | ||
"""Extract the path part from a URI such as site['SITE_URL']. | ||
|
||
The path returned doesn't end 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to
nikola/utils.py
.