Skip to content
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

feat: fix the use of vite.base in Astro Dev Server #13003

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/fresh-badgers-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

nginx proxy pass dev mode
chaegumi marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ type AstroContainerConstructor = {
streaming?: boolean;
renderers?: SSRLoadedRenderer[];
manifest?: AstroContainerManifest;
config?: any;
chaegumi marked this conversation as resolved.
Show resolved Hide resolved
resolve?: SSRResult['resolve'];
astroConfig?: AstroConfig;
};
Expand All @@ -263,6 +264,7 @@ export class experimental_AstroContainer {
private constructor({
streaming = false,
manifest,
config,
renderers,
resolve,
astroConfig,
Expand All @@ -273,6 +275,7 @@ export class experimental_AstroContainer {
dest: nodeLogDestination,
}),
manifest: createManifest(manifest, renderers),
config,
streaming,
serverLike: true,
renderers: renderers ?? manifest?.renderers ?? [],
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/container/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ export class ContainerPipeline extends Pipeline {
static create({
logger,
manifest,
config,
renderers,
resolve,
serverLike,
streaming,
}: Pick<
ContainerPipeline,
'logger' | 'manifest' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'
'logger' | 'manifest' | 'config' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'
>) {
return new ContainerPipeline(
logger,
manifest,
config,
'development',
renderers,
resolve,
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class App {
return AppPipeline.create(manifestData, {
logger: this.#logger,
manifest: this.#manifest,
config: {},
runtimeMode: 'production',
renderers: this.#manifest.renderers,
defaultRoutes: createDefaultRoutes(this.#manifest),
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/src/core/app/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AppPipeline extends Pipeline {
{
logger,
manifest,
config,
runtimeMode,
renderers,
resolve,
Expand All @@ -25,6 +26,7 @@ export class AppPipeline extends Pipeline {
AppPipeline,
| 'logger'
| 'manifest'
| 'config'
| 'runtimeMode'
| 'renderers'
| 'resolve'
Expand All @@ -36,6 +38,7 @@ export class AppPipeline extends Pipeline {
const pipeline = new AppPipeline(
logger,
manifest,
config,
runtimeMode,
renderers,
resolve,
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/base-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class Pipeline {
constructor(
readonly logger: Logger,
readonly manifest: SSRManifest,
readonly config: any,
/**
* "development" or "production" only
*/
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/build/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class BuildPipeline extends Pipeline {
super(
options.logger,
manifest,
config,
options.runtimeMode,
manifest.renderers,
resolve,
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class RenderContext {

async createResult(mod: ComponentInstance) {
const { cookies, pathname, pipeline, routeData, status } = this;
const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve } =
const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve, config } =
pipeline;
const { links, scripts, styles } = await pipeline.headElements(routeData);
const componentMetadata =
Expand All @@ -389,6 +389,7 @@ export class RenderContext {
// calling the render() function will populate the object with scripts, styles, etc.
const result: SSRResult = {
base: manifest.base,
viteBase: config?.vite ? config?.vite.base : '',
cancelled: false,
clientDirectives,
inlinedScripts,
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/src/runtime/server/render/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function renderAllHeadContent(result: SSRResult) {
const scripts = Array.from(result.scripts)
.filter(uniqueElements)
.map((script) => {
if(result.viteBase){
script.props.src = (result.base === '/' ? '' : result.base) + result.viteBase + script.props.src;
}
return renderElement('script', script, false);
});
const links = Array.from(result.links)
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export async function renderScript(result: SSRResult, id: string) {
}

const resolved = await result.resolve(id);
return markHTMLString(`<script type="module" src="${resolved}"></script>`);
return markHTMLString(`<script type="module" src="${result.viteBase ? ((result.base === '/' ? '' : result.base)+result.viteBase) : ''}${resolved}"></script>`);
}
1 change: 1 addition & 0 deletions packages/astro/src/types/public/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export interface SSRResult {
*/
cancelled: boolean;
base: string;
viteBase: string;
styles: Set<SSRElement>;
scripts: Set<SSRElement>;
links: Set<SSRElement>;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class DevPipeline extends Pipeline {
const resolve = createResolve(loader, config.root);
const serverLike = settings.buildOutput === 'server';
const streaming = true;
super(logger, manifest, 'development', [], resolve, serverLike, streaming);
super(logger, manifest, config, 'development', [], resolve, serverLike, streaming);
manifest.serverIslandMap = settings.serverIslandMap;
manifest.serverIslandNameMap = settings.serverIslandNameMap;
}
Expand Down
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading