terraform-aws-serverless-pypi icon indicating copy to clipboard operation
terraform-aws-serverless-pypi copied to clipboard

index.html anchors missing /simple stage

Open roastedramen opened this issue 1 year ago • 9 comments

Using the configuration in the readme the index.html is served at hostname/simple and packages are served at hostname/simple/packagename. Both these two things work, however the index.html served at /simple links to packages without the /simple stage in the url, instead going to hostname/packagename, which does not exist, resulting in a 403 forbidden error when clicked.

roastedramen avatar Aug 10 '23 04:08 roastedramen

thanks for reporting. Must be a related to the switch from HTTP to REST API.

amancevice avatar Aug 10 '23 11:08 amancevice

Hm, I am having trouble replicating this. I deployed the code in /example which essentially matches the README and here is what I get:

curl -s https://{api-id}.execute-api.us-west-2.amazonaws.com/simple/ | prettier --parser html
<!doctype html>
<html>
  <head>
    <meta name="pypi:repository-version" content="1.0" />
    <title>Simple index</title>
  </head>
  <body>
    <h1>Simple index</h1>
    <a href="requests-iamauth">requests-iamauth</a><br />
  </body>
</html>

The href points to a relative path, requests-iamauth, so clicking it should bring me to https://{api-id}.execute-api.us-west-2.amazonaws.com/simple/requests-iamauth.

Could you paste the HTML code from your index.html and the URL you use to access it (feel free to redact the host)

amancevice avatar Aug 10 '23 12:08 amancevice

Thanks for getting back so fast!

Heres the source of our index.html

curl -s 'https://pypi.company.com/simple' | prettier --parser=html

<!doctype html>
<html>
  <head>
    <meta name="pypi:repository-version" content="1.0" />
    <title>Simple index</title>
  </head>
  <body>
    <h1>Simple index</h1>
    <a href="apilib">apilib</a><br /><a href="chalice">chalice</a><br /><a
      href="django-allauth"
      >django-allauth</a
    ><br /><a href="peewee">peewee</a><br /><a href="pyrtemis">pyrtemis</a
    ><br /><a href="skapi">skapi</a><br /><a href="stacklib">stacklib</a><br />
  </body>
</html>

And we access it at https://pypi.company.com/simple (aws_api_gateway_domain_name and aws_api_gateway_base_path_mapping for the domain configured with terraform)

Clicking one of the links on the page (eg peewee) will take us to https://pypi.company.com/peewee, rather than the correct location of https://pypi.company.com/simple/peewee

roastedramen avatar Aug 11 '23 00:08 roastedramen

I wonder if this is a browser issue. Which browser are you using?

Does pip download work for any of these links?

eg,

pip download --no-deps --index-url https://<host>/simple/ <package>

amancevice avatar Aug 11 '23 13:08 amancevice

Seems to occur across different browsers, both firefox and chromium. The pip download command looks like it worked as expected, and using the index in pip generally works, its just the web index that isn't working right

roastedramen avatar Aug 14 '23 01:08 roastedramen

I cannot seem to recreate this issue. I just pushed an update to the example using a custom domain name and base path mapping but it's all working fine for me on Safari and Chromium (Arc).

Could you try manually updating your index.html to add a ./ prefix to the hrefs, push it back up to S3 and try again?

Eg,

aws s3 cp s3://your-pypi-bucket/index.html .
# edit index.html hrefs
aws s3 cp index.html s3://your-pypi-bucket/index.html

amancevice avatar Aug 14 '23 11:08 amancevice

I am having exactly the same issue. Manually adding ./ prefix does not work. Adding simple/ prefix does

magistersart avatar May 08 '24 09:05 magistersart

Can I see the module hcl?

amancevice avatar May 08 '24 22:05 amancevice

module "pypi" { source = "amancevice/serverless-pypi/aws" version = "~> 7"

api_execution_arn = aws_api_gateway_rest_api.pypi.execution_arn api_id = aws_api_gateway_rest_api.pypi.id api_root_resource_id = aws_api_gateway_rest_api.pypi.root_resource_id event_rule_name = "pypi-reindex" iam_role_name = "pypi" lambda_api_fallback_index_url = "https://pypi.org/simple/" lambda_api_function_name = "pypi-api" lambda_reindex_function_name = "pypi-reindex" lambda_reindex_timeout = 14 log_group_api_retention_in_days = 14 log_group_reindex_retention_in_days = 14 s3_bucket_name = "******" }

magistersart avatar May 12 '24 13:05 magistersart