Skip to content

Commit

Permalink
pass manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Jan 24, 2022
1 parent e788b66 commit 7eda31b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { stringifyRequest } from '../../stringify-request'

export default async function middlewareSSRLoader(this: any) {
const {
config,
absolutePagePath,
absoluteAppPath,
absoluteDocumentPath,
Expand Down Expand Up @@ -51,7 +52,8 @@ export default async function middlewareSSRLoader(this: any) {
reactLoadableManifest,
rscManifest,
isServerComponent: ${isServerComponent},
restRenderOpts: ${JSON.stringify(restRenderOpts)}
restRenderOpts: ${JSON.stringify(restRenderOpts)},
config: ${JSON.stringify(config)}
})
export default function rscMiddleware(opts) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { NextRequest } from '../../../../server/web/spec-extension/request'
import type { NextRequest } from '../../../../server/web/spec-extension/request'
import type { NextConfig } from '../../../../types'

import { renderToHTML } from '../../../../server/web/render'
import RenderResult from '../../../../server/render-result'
import { toNodeHeaders } from '../../../../server/web/utils'

// import WebServer from '../../../../server/web-server'
import WebServer from '../../../../server/web-server'

const createHeaders = (args?: any) => ({
...args,
Expand All @@ -29,6 +31,7 @@ export function getRender({
reactLoadableManifest,
isServerComponent,
restRenderOpts,
config,
}: {
App: any
Document: any
Expand All @@ -39,9 +42,13 @@ export function getRender({
reactLoadableManifest: any
isServerComponent: boolean
restRenderOpts: any
config: NextConfig
}) {
// const server = new WebServer({

// })
console.log(config)

return async function render(request: NextRequest) {
const { nextUrl: url, cookies, headers } = request
const { pathname, searchParams } = url
Expand Down
11 changes: 6 additions & 5 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export default abstract class Server {
): void

protected abstract loadEnvConfig(params: { dev: boolean }): void
protected abstract loadManifests(options: any): Manifests

public constructor({
dir = '.',
Expand All @@ -260,11 +261,11 @@ export default abstract class Server {
customServer = true,
hostname,
port,
//
prerenderManifest,
}: Options & Manifests) {
// Assign manifest files
this.prerenderManifest = prerenderManifest
manifestOpts,
}: Options & { manifestOpts?: Manifests }) {
// Assign manifest files if provided, otherwise we load them.
const manifests = this.loadManifests(manifestOpts)
this.prerenderManifest = manifests.prerenderManifest

this.dir = resolve(dir)
this.quiet = quiet
Expand Down
1 change: 1 addition & 0 deletions packages/next/server/dev/hot-reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ export default class HotReloader {
canonicalBase: this.config.amp.canonicalBase,
i18n: this.config.i18n,
previewProps: this.previewProps,
confg: this.config,
} as any)}!`,
isServer: false,
isServerWeb: true,
Expand Down
21 changes: 4 additions & 17 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import type { MiddlewareManifest } from '../build/webpack/plugins/middleware-plu
import type RenderResult from './render-result'
import type { FetchEventResult } from './web/types'
import type { ParsedNextUrl } from '../shared/lib/router/utils/parse-next-url'
import type { PrerenderManifest } from '../build'
import type { Rewrite } from '../lib/load-custom-routes'
import type { NextConfigComplete } from './config-shared'

import { execOnce } from '../shared/lib/utils'
import {
Expand Down Expand Up @@ -92,17 +90,9 @@ export interface NodeRequestHandler {
}

export default class NextNodeServer extends BaseServer {
// @TODO: The following line can be removed once we have TS 4.6 upgraded:
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-6-beta/#code-before-super
// @ts-expect-error
constructor(options: Options) {
// Load manifest files
const dir = resolve(options.dir || '.')
const distDir = join(dir, (options.conf as NextConfigComplete).distDir)
const prerenderManifest = require(join(distDir, PRERENDER_MANIFEST))

// Initialize super class
super({ ...options, prerenderManifest })
super(options)

/**
* This sets environment variable to be used at the time of SSR by head.tsx.
Expand Down Expand Up @@ -1182,13 +1172,10 @@ export default class NextNodeServer extends BaseServer {
return result
}

private _cachedPreviewManifest: PrerenderManifest | undefined
protected getPrerenderManifest(): PrerenderManifest {
if (this._cachedPreviewManifest) {
return this._cachedPreviewManifest
protected loadManifests() {
return {
prerenderManifest: require(join(this.distDir, PRERENDER_MANIFEST)),
}
const manifest = require(join(this.distDir, PRERENDER_MANIFEST))
return (this._cachedPreviewManifest = manifest)
}

protected getRoutesManifest() {
Expand Down
6 changes: 5 additions & 1 deletion packages/next/server/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import type { Options, Manifests } from './base-server'
import BaseServer from './base-server'

export default class NextWebServer extends BaseServer {
constructor(options: Options & Manifests) {
// For the web server, we provide the manifests directly via the constructor.
constructor(options: Options & { manifestOpts: Manifests }) {
super(options)
}
protected loadManifests(manifests: Manifests) {
return manifests
}
protected generateRewrites() {
// @TODO: assuming minimal mode right now
return {
Expand Down

0 comments on commit 7eda31b

Please sign in to comment.