Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions src/utils/detect-server-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,34 +259,16 @@ const detectServerSettings = async (
): Promise<ServerSettings> => {
validateProperty(devConfig, 'framework', 'string')

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO(serhalp): Set to `BaseServerSettings`. Good luck!
let settings: any = {}
let settings: BaseServerSettings

if (flags.dir || devConfig.framework === '#static') {
// serving files statically without a framework server
settings = await handleStaticServer({ flags, devConfig, workingDir: command.workingDir })
} else if (devConfig.framework === '#auto') {
// this is the default CLI behavior

const runDetection = !hasCommandAndTargetPort(devConfig)
const frameworkSettings = runDetection
? getSettingsFromDetectedSettings(command, await detectFrameworkSettings(command, 'dev'))
: undefined
if (frameworkSettings === undefined && runDetection) {
log(`${NETLIFYDEVWARN} No app server detected. Using simple static server`)
settings = await handleStaticServer({ flags, devConfig, workingDir: command.workingDir })
} else {
validateFrameworkConfig({ devConfig })

settings = await mergeSettings({ devConfig, frameworkSettings, workingDir: command.workingDir })
}

settings.plugins = frameworkSettings?.plugins
} else if (devConfig.framework === '#custom') {
validateFrameworkConfig({ devConfig })
// when the users wants to configure `command` and `targetPort`
settings = handleCustomFramework({ devConfig, workingDir: command.workingDir })
} else if (devConfig.framework) {
} else if (devConfig.framework && devConfig.framework !== '#auto') {
validateFrameworkConfig({ devConfig })
// this is when the user explicitly configures a framework, e.g. `framework = "gatsby"`
settings = await handleForcedFramework({
Expand All @@ -296,6 +278,22 @@ const detectServerSettings = async (
workingDir: command.workingDir,
workspacePackage: command.workspacePackage,
})
} else {
// this is the default CLI behavior (#auto or undefined)
const runDetection = !hasCommandAndTargetPort(devConfig)
const frameworkSettings = runDetection
? getSettingsFromDetectedSettings(command, await detectFrameworkSettings(command, 'dev'))
: undefined

if (frameworkSettings === undefined && runDetection) {
log(`${NETLIFYDEVWARN} No app server detected. Using simple static server`)
settings = await handleStaticServer({ flags, devConfig, workingDir: command.workingDir })
} else {
validateFrameworkConfig({ devConfig })

const mergedSettings = await mergeSettings({ devConfig, frameworkSettings, workingDir: command.workingDir })
settings = { ...mergedSettings, plugins: frameworkSettings?.plugins }
}
}

validateConfiguredPort({ devConfig, detectedPort: settings.frameworkPort })
Expand Down
Loading