Skip to content

Commit

Permalink
Updates based on initial code review
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Mar 24, 2022
1 parent 675886d commit d2c0f04
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
15 changes: 4 additions & 11 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ComponentInstance, EndpointHandler, ManifestData, RouteData } from '../../@types/astro';
import type { SSRManifest as Manifest, RouteInfo } from './types';

import { getType as getMimeType } from 'mime';
import { defaultLogOptions } from '../logger.js';
export { deserializeManifest } from './common.js';
import { matchRoute } from '../routing/match.js';
Expand All @@ -10,10 +11,6 @@ import { RouteCache } from '../render/route-cache.js';
import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from '../render/ssr-element.js';
import { prependForwardSlash } from '../path.js';

const supportedFileNameToMimeTypes = new Map<string, string>([
['json', 'application/json']
]);

export class App {
#manifest: Manifest;
#manifestData: ManifestData;
Expand All @@ -28,7 +25,6 @@ export class App {
};
this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route]));
this.#routeCache = new RouteCache(defaultLogOptions);
this
}
match(request: Request): RouteData | undefined {
const url = new URL(request.url);
Expand Down Expand Up @@ -121,13 +117,10 @@ export class App {
return result.response;
} else {
const body = result.body;
const ext = /\.([a-z]+)/.exec(url.pathname);
const headers = new Headers();
if(ext) {
const mime = supportedFileNameToMimeTypes.get(ext[1]);
if(mime) {
headers.set('Content-Type', mime);
}
const mimeType = getMimeType(url.pathname);
if(mimeType) {
headers.set('Content-Type', mimeType);
}
const bytes = this.#encoder.encode(body);
headers.set('Content-Length', bytes.byteLength.toString());
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export async function loadManifest(rootFolder: URL): Promise<SSRManifest> {

export async function loadApp(rootFolder: URL): Promise<NodeApp> {
const manifest = await loadManifest(rootFolder);
return new NodeApp(manifest, rootFolder);
return new NodeApp(manifest);
}
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function staticBuild(opts: StaticBuildOptions) {

if (opts.buildConfig.staticMode) {
await generatePages(ssrResult, opts, internals, facadeIdToPageDataMap);
//await cleanSsrOutput(opts);
await cleanSsrOutput(opts);
} else {
await ssrMoveAssets(opts);
}
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ if(_start in adapter) {
chunk.code = code.replace(exp, () => {
return JSON.stringify(manifest);
});
chunk.fileName = 'entry.mjs';
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ polyfill(globalThis, {
});

export function createExports(manifest: SSRManifest) {
const app = new NodeApp(manifest, new URL(import.meta.url));
const app = new NodeApp(manifest);
return {
async handler(req: IncomingMessage, res: ServerResponse, next?: (err?: unknown) => void) {
const route = app.match(req);
Expand Down

0 comments on commit d2c0f04

Please sign in to comment.