@@ -2,4 +2,4 @@
|
||||
# Minimal config. version is the only required field.
|
||||
version = 1
|
||||
merge.automerge_label = "0 - <(^_^)> - merge it! ✌️"
|
||||
approve.auto_approve_usernames = ["flybayer", "depfu"]
|
||||
approve.auto_approve_usernames = ["flybayer", "beerose", "depfu"]
|
||||
|
||||
@@ -1188,9 +1188,6 @@ export default async function getBaseWebpackConfig(
|
||||
}
|
||||
: {}),
|
||||
'process.env.__BLITZ_SUSPENSE_ENABLED': JSON.stringify(hasReactRoot),
|
||||
'process.env.__BLITZ_SESSION_COOKIE_PREFIX': JSON.stringify(
|
||||
sessionCookiePrefix
|
||||
),
|
||||
'process.env.__NEXT_TRAILING_SLASH': JSON.stringify(
|
||||
config.trailingSlash
|
||||
),
|
||||
@@ -1240,7 +1237,11 @@ export default async function getBaseWebpackConfig(
|
||||
// pre-webpack era (common in server-side code)
|
||||
'global.GENTLY': JSON.stringify(false),
|
||||
}
|
||||
: undefined),
|
||||
: {
|
||||
'process.env.__BLITZ_SESSION_COOKIE_PREFIX': JSON.stringify(
|
||||
sessionCookiePrefix
|
||||
),
|
||||
}),
|
||||
// stub process.env with proxy to warn a missing value is
|
||||
// being accessed in development mode
|
||||
...(config.experimental.pageEnv && dev
|
||||
|
||||
@@ -2,11 +2,11 @@ import { parse as parseUrl } from 'url'
|
||||
import { IncomingMessage, ServerResponse } from 'http'
|
||||
import { apiResolver } from '../../../../server/api-utils'
|
||||
import { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils'
|
||||
import { loadConfigProduction } from '../../../../server/config-shared'
|
||||
import { loadConfigAtRuntime } from '../../../../server/config-shared'
|
||||
import { DecodeError } from '../../../../shared/lib/utils'
|
||||
|
||||
export function getApiHandler(ctx: ServerlessHandlerCtx) {
|
||||
const { page, pagesDir, pageModule, encodedPreviewProps, pageIsDynamic } = ctx
|
||||
const { page, pageModule, encodedPreviewProps, pageIsDynamic } = ctx
|
||||
const {
|
||||
handleRewrites,
|
||||
handleBasePath,
|
||||
@@ -14,7 +14,7 @@ export function getApiHandler(ctx: ServerlessHandlerCtx) {
|
||||
normalizeDynamicRouteParams,
|
||||
} = getUtils(ctx)
|
||||
|
||||
const config = loadConfigProduction(pagesDir)
|
||||
const config = loadConfigAtRuntime()
|
||||
|
||||
return async (req: IncomingMessage, res: ServerResponse) => {
|
||||
try {
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
} from '../../../../shared/lib/constants'
|
||||
import { trace } from '../../../../telemetry/trace'
|
||||
import { normalizePathSep } from '../../../../server/normalize-page-path'
|
||||
import { getSessionCookiePrefix } from '../../../../server/lib/utils'
|
||||
import { loadConfigProduction } from '../../../../server/config-shared'
|
||||
|
||||
export type ServerlessLoaderQuery = {
|
||||
page: string
|
||||
@@ -62,6 +64,17 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
|
||||
|
||||
const pagesDir = normalizePathSep(rawPagesDir)
|
||||
|
||||
const sessionCookiePrefix = getSessionCookiePrefix(
|
||||
loadConfigProduction(pagesDir)
|
||||
)
|
||||
|
||||
const setEnvCode = `
|
||||
process.env.BLITZ_APP_DIR = process.env.VERCEL && !process.env.CI
|
||||
? '/var/task/'
|
||||
: "${pagesDir}"
|
||||
process.env.__BLITZ_SESSION_COOKIE_PREFIX = "${sessionCookiePrefix}"
|
||||
`
|
||||
|
||||
const buildManifest = join(distDir, BUILD_MANIFEST).replace(/\\/g, '/')
|
||||
const reactLoadableManifest = join(
|
||||
distDir,
|
||||
@@ -109,7 +122,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
|
||||
|
||||
import { getApiHandler } from 'next/dist/build/webpack/loaders/next-serverless-loader/api-handler'
|
||||
|
||||
process.env.BLITZ_APP_DIR = "${pagesDir}"
|
||||
${setEnvCode}
|
||||
|
||||
const combinedRewrites = Array.isArray(routesManifest.rewrites)
|
||||
? routesManifest.rewrites
|
||||
@@ -129,7 +142,6 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
|
||||
basePath: "${basePath}",
|
||||
pageIsDynamic: ${pageIsDynamicRoute},
|
||||
encodedPreviewProps: ${encodedPreviewProps},
|
||||
pagesDir: "${pagesDir}",
|
||||
})
|
||||
export default apiHandler
|
||||
`
|
||||
@@ -148,7 +160,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
|
||||
}
|
||||
import { getPageHandler } from 'next/dist/build/webpack/loaders/next-serverless-loader/page-handler'
|
||||
|
||||
process.env.BLITZ_APP_DIR = "${pagesDir}"
|
||||
${setEnvCode}
|
||||
|
||||
const documentModule = require("${absoluteDocumentPath}")
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ export const vercelHeader = 'x-vercel-id'
|
||||
|
||||
export type ServerlessHandlerCtx = {
|
||||
page: string
|
||||
pagesDir: string
|
||||
|
||||
pageModule: any
|
||||
pageComponent?: any
|
||||
|
||||
@@ -25,9 +25,12 @@ export function loadConfigAtRuntime() {
|
||||
export function loadConfigProduction(pagesDir: string): NextConfigComplete {
|
||||
let userConfigModule
|
||||
try {
|
||||
const path = join(pagesDir, CONFIG_FILE)
|
||||
debug('Loading config from ', path)
|
||||
// eslint-disable-next-line no-eval -- block webpack from following this module path
|
||||
userConfigModule = eval('require')(join(pagesDir, CONFIG_FILE))
|
||||
userConfigModule = eval('require')(path)
|
||||
} catch {
|
||||
debug('Did not find custom config file')
|
||||
// In case user does not have custom config
|
||||
userConfigModule = {}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,17 @@ export function getAndValidateMiddleware(
|
||||
route: string
|
||||
) {
|
||||
const middleware: Middleware[] = []
|
||||
debug('[getAndValidateMiddleware] config.middleware', config.middleware)
|
||||
if (config.middleware) {
|
||||
if (!Array.isArray(config.middleware)) {
|
||||
throw new Error("'middleware' in blitz.config.js must be an array")
|
||||
}
|
||||
middleware.push(...config.middleware)
|
||||
}
|
||||
debug(
|
||||
'[getAndValidateMiddleware] resolverModule.middleware',
|
||||
resolverModule.middleware
|
||||
)
|
||||
if (resolverModule.middleware) {
|
||||
if (!Array.isArray(resolverModule.middleware)) {
|
||||
throw new Error(`'middleware' exported from ${route} must be an array`)
|
||||
|
||||
@@ -47,3 +47,14 @@ export function resultToChunks(result: RenderResult): Promise<string[]> {
|
||||
export const isInternalDevelopment = __dirname.match(
|
||||
/[\\/]packages[\\/]next[\\/]dist[\\/]server$/
|
||||
)
|
||||
|
||||
export const fixNodeFileTrace = () => {
|
||||
const path = require('path')
|
||||
path.resolve('.blitz.config.compiled.js')
|
||||
path.resolve('.next/server/blitz-db.js')
|
||||
path.resolve('.next/serverless/blitz-db.js')
|
||||
}
|
||||
export const withFixNodeFileTrace = (fn: Function) => {
|
||||
fixNodeFileTrace()
|
||||
return fn
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ function transformPropGetters(
|
||||
}
|
||||
|
||||
const HOFName = 'withFixNodeFileTrace';
|
||||
const importFrom = '@blitzjs/core/server';
|
||||
const importFrom = 'next/dist/server/utils';
|
||||
|
||||
function addWithFixNodeFileTraceImport(path: NodePath<any>) {
|
||||
return addNamedImport(path, HOFName, importFrom);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
|
||||
function HealthCheck(_req, res) {
|
||||
res.status(200).send('ok');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getServerSideProps = _withFixNodeFileTrace(async () => {
|
||||
const products = [
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getStaticProps = _withFixNodeFileTrace(() => ({
|
||||
props: {
|
||||
today: new Date(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getStaticProps = _withFixNodeFileTrace(async () => {
|
||||
const products = [
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getStaticProps = _withFixNodeFileTrace(
|
||||
async function getStaticProps() {
|
||||
const products = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getServerSideProps = _withFixNodeFileTrace(
|
||||
async function getServerSideProps() {
|
||||
const products = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getServerSideProps = _withFixNodeFileTrace(async () => {
|
||||
const products = [
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from '@blitzjs/core/server';
|
||||
import { withFixNodeFileTrace as _withFixNodeFileTrace } from 'next/dist/server/utils';
|
||||
export const getServerSideProps = _withFixNodeFileTrace(async () => {
|
||||
const products = [
|
||||
{
|
||||
|
||||
@@ -5,14 +5,3 @@
|
||||
*/
|
||||
export {resolver} from "./resolver"
|
||||
export type {AuthenticatedMiddlewareCtx} from "./resolver"
|
||||
|
||||
export const fixNodeFileTrace = () => {
|
||||
const path = require("path")
|
||||
path.resolve(".blitz.config.compiled.js")
|
||||
path.resolve(".next/server/blitz-db.js")
|
||||
path.resolve(".next/serverless/blitz-db.js")
|
||||
}
|
||||
export const withFixNodeFileTrace = (fn: Function) => {
|
||||
fixNodeFileTrace()
|
||||
return fn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user