(cwd: string, options: DevServerOptions)
| 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 |
nothing calls this directly
no test coverage detected