Skip to content

Commit 4da26e3

Browse files
committed
chore: update constants for clarity
1 parent ee5f379 commit 4da26e3

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

src/handlers/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { toComputeResponse, toReqRes } from '@fastly/http-compute-js'
22
import type { NextConfigComplete } from 'next/dist/server/config-shared.js'
33
import type { WorkerRequestHandler } from 'next/dist/server/lib/types.js'
44

5-
import { TASK_DIR } from '../helpers/constants.js'
5+
import { RUN_DIR } from '../helpers/constants.js'
66
import { setCacheControlHeaders, setVaryHeaders } from '../helpers/headers.js'
77

88
let nextHandler: WorkerRequestHandler, nextConfig: NextConfigComplete
@@ -19,7 +19,7 @@ export default async (request: Request) => {
1919
;[nextHandler] = await getRequestHandlers({
2020
port: 3000,
2121
hostname: 'localhost',
22-
dir: TASK_DIR,
22+
dir: RUN_DIR,
2323
isDev: false,
2424
})
2525
}

src/helpers/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises'
22

33
import { NextConfigComplete } from 'next/dist/server/config-shared.js'
44

5-
import { TASK_DIR } from './constants.js'
5+
import { RUN_DIR } from './constants.js'
66

77
/**
88
* Enable Next.js standalone mode at build time
@@ -16,7 +16,7 @@ export const setBuildConfig = () => {
1616
*/
1717
export const getRunConfig = async () => {
1818
// get config from the build output
19-
return JSON.parse(await readFile(`${TASK_DIR}/.next/required-server-files.json`, 'utf-8')).config
19+
return JSON.parse(await readFile(`${RUN_DIR}/.next/required-server-files.json`, 'utf-8')).config
2020
}
2121

2222
/**
@@ -26,7 +26,7 @@ export const setRunConfig = (config: NextConfigComplete) => {
2626
// set the path to the cache handler
2727
config.experimental = {
2828
...config.experimental,
29-
incrementalCacheHandlerPath: `${TASK_DIR}/dist/handlers/cache.cjs`,
29+
incrementalCacheHandlerPath: `${RUN_DIR}/dist/handlers/cache.cjs`,
3030
}
3131

3232
// set config

src/helpers/constants.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { fileURLToPath } from 'node:url'
33

44
export const MODULE_DIR = fileURLToPath(new URL('.', import.meta.url))
55
export const PLUGIN_DIR = resolve(`${MODULE_DIR}../..`)
6-
export const TASK_DIR = process.cwd()
6+
export const WORKING_DIR = process.cwd()
77

8-
export const BUILD_DIR = `${TASK_DIR}/.netlify/.next`
9-
10-
export const FUNCTIONS_DIR = `${TASK_DIR}/.netlify/functions-internal`
11-
export const EDGE_FUNCTIONS_DIR = `${TASK_DIR}/.netlify/edge-functions`
8+
export const BUILD_DIR = `${WORKING_DIR}/.netlify/.next`
9+
export const RUN_DIR = WORKING_DIR
1210

11+
export const SERVER_FUNCTIONS_DIR = `${WORKING_DIR}/.netlify/functions-internal`
1312
export const SERVER_HANDLER_NAME = '___netlify-server-handler'
14-
export const SERVER_HANDLER_DIR = `${FUNCTIONS_DIR}/${SERVER_HANDLER_NAME}`
13+
export const SERVER_HANDLER_DIR = `${SERVER_FUNCTIONS_DIR}/${SERVER_HANDLER_NAME}`
14+
15+
export const EDGE_FUNCTIONS_DIR = `${WORKING_DIR}/.netlify/edge-functions`
16+
export const EDGE_HANDLER_NAME = '___netlify-edge-handler'
17+
export const EDGE_HANDLER_DIR = `${EDGE_FUNCTIONS_DIR}/${EDGE_HANDLER_NAME}`

src/helpers/functions.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { writeFile } from 'fs/promises'
33
import { nodeFileTrace } from '@vercel/nft'
44
import { copy, emptyDir, readJson, writeJSON } from 'fs-extra/esm'
55

6-
import { BUILD_DIR, SERVER_HANDLER_DIR, SERVER_HANDLER_NAME, PLUGIN_DIR } from './constants.js'
6+
import {
7+
BUILD_DIR,
8+
EDGE_HANDLER_DIR,
9+
PLUGIN_DIR,
10+
SERVER_HANDLER_DIR,
11+
SERVER_HANDLER_NAME,
12+
} from './constants.js'
713

814
const pkg = await readJson(`${PLUGIN_DIR}/package.json`)
915

@@ -61,5 +67,6 @@ export const createServerHandler = async () => {
6167
* Create a Netlify edge function to run the Next.js server
6268
*/
6369
export const createEdgeHandler = async () => {
64-
// TODO: implement
70+
// reset the handler directory
71+
await emptyDir(EDGE_HANDLER_DIR)
6572
}

0 commit comments

Comments
 (0)