Repository navigation
|
Due to deployment requirements, I need to use the static-adapter to build static web pages and support configurable web and API prefixes. The configuration is divided into two parts:
1. My current solution1.1 Page routingPage routing by default uses relative paths, so I only need to add prefixes in the reverse proxy server. 1.2 Configuration fileI added a window.CONFIG = {
apiPrefix: "/app/api/v1",
pagePrefix: "/app",
};Then, I added the following in <head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
+ <script src="./config.js"></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">This way, when I run When deploying, I can modify the configuration by replacing the config.js file. 2. The problem encounteredHowever, with this approach, it always looks for
3. Subsequent solution ideasI noticed that
I think I should also be able to use a similar method to calculate the location of the config.js file 4. Other attempted solutions4.1 .envUsing a I noticed that 4.2 Use the configuration provided by the backendThis is a deadlock, because my backend API may need the prefix configured by the frontend. Reference |
Replies: 1 comment
|
Use SvelteKit's asset placeholder instead of a route-relative literal: <script src="%sveltekit.assets%/config.js"></script>Keep |
Use SvelteKit's asset placeholder instead of a route-relative literal:
Keep
config.jsinstatic/. During generation,%sveltekit.assets%becomespaths.assetswhen configured, otherwise the correct relative path topaths.base, so nested pages do not resolve it from their own directory. This is the documentedapp.htmlplaceholder: https://svelte.dev/docs/kit/project-structure#Project-files-src-app.html