Skip to content

Commit

Permalink
add routes and pages manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Jan 24, 2022
1 parent 7eda31b commit 0b6f93e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
19 changes: 11 additions & 8 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export interface Options {

export interface Manifests {
prerenderManifest: PrerenderManifest
routesManifest: CustomRoutes
pagesManifest: PagesManifest | undefined
}

export interface BaseRequestHandler {
Expand Down Expand Up @@ -171,12 +173,13 @@ export default abstract class Server {
protected middlewareManifest?: MiddlewareManifest
protected middleware?: RoutingItem[]
protected prerenderManifest: PrerenderManifest
protected routesManifest: CustomRoutes

public readonly hostname?: string
public readonly port?: number

protected abstract getPublicDir(): string
protected abstract getHasStaticDir(): boolean
protected abstract getPagesManifest(): PagesManifest | undefined
protected abstract getBuildId(): string
protected abstract generatePublicRoutes(): Route[]
protected abstract generateImageRoutes(): Route[]
Expand Down Expand Up @@ -213,7 +216,6 @@ export default abstract class Server {
protected abstract getPagePath(pathname: string, locales?: string[]): string
protected abstract getFontManifest(): FontManifest | undefined
protected abstract getMiddlewareManifest(): MiddlewareManifest | undefined
protected abstract getRoutesManifest(): CustomRoutes

protected abstract sendRenderResult(
req: BaseNextRequest,
Expand Down Expand Up @@ -263,10 +265,6 @@ export default abstract class Server {
port,
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
this.loadEnvConfig({ dev })
Expand All @@ -280,6 +278,12 @@ export default abstract class Server {
this.publicDir = this.getPublicDir()
this.hasStaticDir = !minimalMode && this.getHasStaticDir()

// Assign manifest files if provided, otherwise we load them.
const manifests = this.loadManifests(manifestOpts)
this.prerenderManifest = manifests.prerenderManifest
this.routesManifest = manifests.routesManifest
this.pagesManifest = manifests.pagesManifest

// Only serverRuntimeConfig needs the default
// publicRuntimeConfig gets it's default in client/index.js
const {
Expand Down Expand Up @@ -332,7 +336,6 @@ export default abstract class Server {
publicRuntimeConfig,
})

this.pagesManifest = this.getPagesManifest()
this.middlewareManifest = this.getMiddlewareManifest()

this.customRoutes = this.getCustomRoutes()
Expand Down Expand Up @@ -599,7 +602,7 @@ export default abstract class Server {
}

protected getCustomRoutes(): CustomRoutes {
const customRoutes = this.getRoutesManifest()
const customRoutes = { ...this.routesManifest }
let rewrites: CustomRoutes['rewrites']

// rewrites can be stored as an array when an array is
Expand Down
6 changes: 2 additions & 4 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,10 +1175,8 @@ export default class NextNodeServer extends BaseServer {
protected loadManifests() {
return {
prerenderManifest: require(join(this.distDir, PRERENDER_MANIFEST)),
routesManifest: require(join(this.distDir, ROUTES_MANIFEST)),
pagesManifest: this.getPagesManifest(),
}
}

protected getRoutesManifest() {
return require(join(this.distDir, ROUTES_MANIFEST))
}
}
15 changes: 0 additions & 15 deletions packages/next/server/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ export default class NextWebServer extends BaseServer {
protected handleCompression() {
// @TODO
}
protected getRoutesManifest() {
return {
headers: [],
rewrites: {
fallback: [],
afterFiles: [],
beforeFiles: [],
},
redirects: [],
}
}
protected getPagePath() {
// @TODO
return ''
Expand Down Expand Up @@ -83,10 +72,6 @@ export default class NextWebServer extends BaseServer {
protected getMiddlewareManifest() {
return undefined
}
protected getPagesManifest() {
// @TODO
return undefined
}
protected getFilesystemPaths() {
return new Set<string>()
}
Expand Down

0 comments on commit 0b6f93e

Please sign in to comment.