Skip to content

Commit

Permalink
fix: origin schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Dec 25, 2024
1 parent ae98d3a commit fe7897c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/server/middlewares/htmlFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function htmlFallbackMiddleware(
}
const url = cleanUrl(req.url);
const pathname = removeSlash(decodeURIComponent(url));
const headers = app.resolvedUserConfig.server.headers;
const headers = app.config.server.headers;

if (pathname.endsWith('.html')) {
const html = app.compiler.resource(pathname);
Expand Down
14 changes: 5 additions & 9 deletions packages/core/src/server/middlewares/lazyCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function lazyCompilationMiddleware(
app: Server
): Connect.NextHandleFunction {
return async function handleLazyCompilationMiddleware(req, res, next) {
const { resolvedUserConfig, compiler } = app;
const { config, compiler } = app;

if (!req.url.startsWith(DEFAULT_LAZY_COMPILATION_PATH)) {
return await next();
Expand All @@ -44,7 +44,7 @@ export function lazyCompilationMiddleware(
})
.join(', ');

resolvedUserConfig.logger.info(
config.logger.info(
`${bold(green('✨Lazy compiling'))} ${bold(cyan(pathsStr))}`,
true
);
Expand All @@ -62,19 +62,15 @@ export function lazyCompilationMiddleware(
return next();
}

if (isNodeEnvironment || resolvedUserConfig.server.writeToDisk) {
if (isNodeEnvironment || config.server.writeToDisk) {
compiler.writeResourcesToDisk();
}

resolvedUserConfig.logger.info(
config.logger.info(
`${bold(green(`✓ Lazy compilation done`))} ${bold(
cyan(pathsStr)
)} in ${bold(
green(
resolvedUserConfig.logger.formatExecutionTime(
performance.now() - start
)
)
green(config.logger.formatExecutionTime(performance.now() - start))
)}.`
);

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function proxyMiddleware(
middlewareServer: HttpServer,
config: NonNullable<CommonServerOptions['proxy']>
): Connect.NextHandleFunction {
const { resolvedUserConfig } = app;
const { config: resolvedUserConfig } = app;

const proxies: Record<string, [Server, ProxyOptions]> = {};
Object.keys(config).forEach((context) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/middlewares/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function resourceMiddleware(app: Server): Connect.NextHandleFunction {
return next();
}
const url = cleanUrl(req.url);
const { compiler, resolvedUserConfig: config, publicPath } = app;
const { compiler, config, publicPath } = app;

if (compiler._isInitialCompile) {
await compiler.waitForInitialCompileFinish();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import sirv, { Options } from 'sirv';
import type { Server } from '../index.js';

export function staticMiddleware(app: Server): Connect.NextHandleFunction {
const { resolvedUserConfig, compiler } = app;
const { config, compiler } = app;
const root = compiler.config.root;
const serve = sirv(
root,
sirvOptions({
getHeaders: () => resolvedUserConfig.server.headers
getHeaders: () => config.server.headers
})
);
return function handleStaticMiddleware(req, res, next) {
Expand Down Expand Up @@ -61,7 +61,7 @@ export function staticMiddleware(app: Server): Connect.NextHandleFunction {
}

export function publicMiddleware(app: Server): Connect.NextHandleFunction {
const { resolvedUserConfig: config, publicDir, publicFiles } = app;
const { config: config, publicDir, publicFiles } = app;
const serve = sirv(
publicDir,
sirvOptions({
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/server/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface PreviewServerOptions extends CommonServerOptions {
* @class
*/
export class PreviewServer extends httpServer {
resolvedUserConfig: ResolvedUserConfig;
config: ResolvedUserConfig;
previewServerOptions: PreviewServerOptions;
httpsOptions: SecureServerOptions;

Expand All @@ -77,15 +77,15 @@ export class PreviewServer extends httpServer {
* @throws {Error} If the server cannot be started.
*/
async createPreviewServer(): Promise<void> {
this.resolvedUserConfig = await resolveConfig(
this.config = await resolveConfig(
this.inlineConfig,
'preview',
'production',
'production',
true
);

this.logger = this.resolvedUserConfig.logger;
this.logger = this.config.logger;

await this.#resolveOptions();

Expand Down Expand Up @@ -115,7 +115,7 @@ export class PreviewServer extends httpServer {
*/
#initializeMiddlewares() {
const { cors, proxy } = this.previewServerOptions;
const { appType, middlewareMode } = this.resolvedUserConfig.server;
const { appType, middlewareMode } = this.config.server;

if (cors !== false) {
this.app.use(corsMiddleware(typeof cors === 'boolean' ? {} : cors));
Expand Down Expand Up @@ -154,7 +154,7 @@ export class PreviewServer extends httpServer {
const {
server,
compilation: { root, output }
} = this.resolvedUserConfig;
} = this.config;

this.publicPath = output.publicPath ?? '/';
const preview = server?.preview;
Expand All @@ -174,7 +174,7 @@ export class PreviewServer extends httpServer {
this.serve = sirv(distDir, {
etag: true,
dev: true,
single: this.resolvedUserConfig.server.appType === 'spa',
single: this.config.server.appType === 'spa',
ignores: false,
setHeaders: (res, pathname) => {
if (knownJavascriptExtensionRE.test(pathname)) {
Expand Down Expand Up @@ -224,13 +224,13 @@ export class PreviewServer extends httpServer {

this.resolvedUrls = await resolveServerUrls(
this.httpServer,
this.resolvedUserConfig,
this.config,
'preview'
);

const shortFile = getShortName(
this.resolvedUserConfig.configFilePath,
this.resolvedUserConfig.root
this.config.configFilePath,
this.config.root
);
this.logger.info(`Using config file at ${bold(green(shortFile))}`);

Expand Down

0 comments on commit fe7897c

Please sign in to comment.