Sapper: Encode Square Brackets to Support AWS API Gateway

Created on 24 Jul 2019  Â·  5Comments  Â·  Source: sveltejs/sapper

Describe the bug
AWS API Gatway does not support square brackets in URLs. Apps deployed in sapper run beautifully with Lambda + API Gateway, except for the fact that any page with a [slug].js on it will not load.

Suggested Solutions

  • Allow a way to obfuscate the file names to hex when deploying to production.
  • Allow escaping square brackets using %5B for [ and %5D for ]

Most helpful comment

This is a duplicate of #747. There is some more detailed information about this there.

All 5 comments

I'm really not sure what this is asking for. The filenames of your routes in your source files is not something that would typically be at all relevant once your app is built. The square brackets aren't part of your URLs, just part of your original source files before the app is even compiled and bundled.

This is a duplicate of #747. There is some more detailed information about this there.

@Conduitry Okay, let me explain more.

I need to have a file called [slug].js in my application so that it captures everything. When I do an npm build it gets compiled into [slug].somehash.js. AWS API Gateway is broken and doesn't allow you to have square brackets in URLs.

For example, https://staging.everychat.app/ is a sapper application deployed using Lambda and API Gateway. The Svelte app requests https://staging.everychat.app/client/[slug].10b26d5f.js so that it can load the page https://staging.everychat.app/apps/telegram.

If you notice, the JS URL returns 400.

If you escape the JS URL to https://staging.everychat.app/client/%5Bslug%5D.10b26d5f.js it returns 200 and sends the file.

So the original filename is something that is relevant in this case.

@nikhiljha I've run into this before, and there's a workaround. Folders with brackets seem to work on AWS Gateway fine, but not end files. (Strange, yes.)

Instead of

/some/path/[slug].js

You can do

/some/path/[slug]/index.js

Really, we should still try and fix this, but that workaround should save your bacon for now.

I'm going to close this ticket since #747 is already dealing with the topic at hand.

Sadly – and unsurprisingly – even folder-level dynamic segments are a no-go via AWS Gateway directly: /client/[slug]/index.js fails, whilst, /client/%5Bslug%5D/index.js is allowed.

EDIT: ignore that (it's not a valid example) and refer to #747!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

freedmand picture freedmand  Â·  4Comments

Rich-Harris picture Rich-Harris  Â·  3Comments

Rich-Harris picture Rich-Harris  Â·  4Comments

jhuettinger picture jhuettinger  Â·  3Comments

milosdjakovic picture milosdjakovic  Â·  3Comments