MCPcopy Create free account
hub / github.com/vercel/vercel / startDevServer

Function startDevServer

packages/go/src/index.ts:926–1071  ·  view source on GitHub ↗
(
  opts: StartDevServerOptions
)

Source from the content-addressed store, hash-verified

924}
925
926export async function startDevServer(
927 opts: StartDevServerOptions
928): Promise<StartDevServerResult> {
929 const { entrypoint, workPath, config, meta = {} } = opts;
930 const { devCacheDir = join(workPath, '.vercel', 'cache') } = meta;
931
932 // For some reason, if `entrypoint` is a path segment (filename contains `[]`
933 // brackets) then the `.go` suffix on the entrypoint is missing. Fix that here…
934 let entrypointWithExt = entrypoint;
935 if (!entrypoint.endsWith('.go')) {
936 entrypointWithExt += '.go';
937 }
938
939 // Standalone server mode when framework is 'go' or 'services'
940 if (config?.framework === 'go' || config?.framework === 'services') {
941 const resolvedEntrypoint = await detectGoEntrypoint(
942 workPath,
943 entrypointWithExt
944 );
945 if (!resolvedEntrypoint) {
946 throw new Error(
947 `No Go entrypoint found. Expected one of: ${GO_CANDIDATE_ENTRYPOINTS.join(', ')}`
948 );
949 }
950 return startStandaloneDevServer(opts, resolvedEntrypoint);
951 }
952
953 const entrypointDir = dirname(entrypointWithExt);
954 const tmp = join(devCacheDir, 'go', Math.random().toString(32).substring(2));
955 const tmpPackage = join(tmp, entrypointDir);
956 await mkdirp(tmpPackage);
957
958 const { goModPath } = await findGoModPath(
959 join(workPath, entrypointDir),
960 workPath
961 );
962 const modulePath = goModPath ? dirname(goModPath) : undefined;
963 const analyzed = await getAnalyzedEntrypoint({
964 entrypoint: entrypointWithExt,
965 modulePath,
966 workPath,
967 });
968
969 await Promise.all([
970 copyEntrypoint(entrypointWithExt, tmpPackage),
971 copyDevServer(analyzed.functionName, tmpPackage),
972 writeGoMod({
973 destDir: tmp,
974 goModPath,
975 packageName: analyzed.packageName,
976 }),
977 writeGoWork(tmp, workPath, modulePath),
978 ]);
979
980 const portFile = join(
981 TMP,
982 `vercel-dev-port-${Math.random().toString(32).substring(2)}`
983 );

Callers

nothing calls this directly

Calls 15

detectGoEntrypointFunction · 0.90
startStandaloneDevServerFunction · 0.90
getAnalyzedEntrypointFunction · 0.90
cloneEnvFunction · 0.90
createGoFunction · 0.90
debugFunction · 0.90
copyEntrypointFunction · 0.85
copyDevServerFunction · 0.85
writeGoModFunction · 0.85
writeGoWorkFunction · 0.85
spawnFunction · 0.85
retryFunction · 0.85

Tested by

no test coverage detected