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

Method constructor

packages/cli/src/util/dev/server.ts:225–301  ·  view source on GitHub ↗
(cwd: string, options: DevServerOptions)

Source from the content-addressed store, hash-verified

223 }
224
225 constructor(cwd: string, options: DevServerOptions) {
226 this.cwd = cwd;
227 this.repoRoot = options.repoRoot ?? cwd;
228 this.envConfigs = { buildEnv: {}, runEnv: {}, allEnv: {} };
229 this.envValues = options.envValues || {};
230 this.projectId = options.projectId;
231 this.orgId = options.orgId;
232 this.files = {};
233 this.originalProjectSettings = options.projectSettings;
234 this.projectSettings = options.projectSettings;
235 this.services = options.services;
236 this.useImplicitServicesEnvInjection =
237 options.useImplicitServicesEnvInjection ?? true;
238 this.caseSensitive = false;
239 this.apiDir = null;
240 this.apiExtensions = new Set();
241
242 this.proxy = httpProxy.createProxyServer({
243 changeOrigin: true,
244 ws: true,
245 xfwd: true,
246 });
247 this.proxy.on('proxyRes', (proxyRes, req) => {
248 // override "server" header, like production
249 proxyRes.headers['server'] = 'Vercel';
250
251 // Apply transform context for response that was stored
252 // before proxying this request
253 const responseTransforms = this.responseTransformsByReq.get(req);
254 if (responseTransforms) {
255 this.responseTransformsByReq.delete(req);
256 applyResponseTransforms(proxyRes.headers, responseTransforms);
257 }
258 });
259 this.proxy.on('error', (err, req, res) => {
260 output.debug(
261 `Proxy error for ${req?.url ?? 'unknown request'}: ${errorToString(err)}`
262 );
263
264 if (!res) {
265 return;
266 }
267
268 if ('destroy' in res && typeof res.destroy === 'function') {
269 res.destroy();
270 return;
271 }
272
273 if (res instanceof http.ServerResponse) {
274 if (!res.headersSent) {
275 res.writeHead(502);
276 }
277 res.end();
278 }
279 });
280
281 this.server = http.createServer(this.devServerHandler);
282 this.server.timeout = 0; // Disable timeout

Callers

nothing calls this directly

Calls 8

applyResponseTransformsFunction · 0.90
errorToStringFunction · 0.90
getVercelDirectoryFunction · 0.90
debugMethod · 0.80
getMethod · 0.65
deleteMethod · 0.45
destroyMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected