http.createServer(function (req, res) { var url = URL.parse(req.url); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(fs.readFileSync(__dirname + url.pathname)); })
// We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. // Webpack needs to know it to put the right <script> hrefs into HTML even in // single-page apps that may serve index.html for nested URLs like /todos/42. // We can't use a relative path in HTML because we don't want to load something // like /todos/42/static/js/bundle.7289d.js. We have to know the root. function getServedPath(appPackageJson) { const publicUrl = getPublicUrl(appPackageJson); const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); return ensureSlash(servedUrl, true); }
// (publicKey -> cert) cache function verifyPublicKeyUrl(publicKeyUrl) { const parsedUrl = url.parse(publicKeyUrl); if (parsedUrl.protocol !== 'https:') { return false; } const hostnameParts = parsedUrl.hostname.split('.'); const length = hostnameParts.length; const domainParts = hostnameParts.slice(length - 2, length); const domain = domainParts.join('.'); return domain === 'apple.com'; }
getStat(req: MyRequest) { const pathname = url.parse(req.originalUrl).pathname; if (pathname === '/') { return req.method.toLocaleLowerCase() + '_' + '/'; } let partArr = pathname.split('/'); partArr = partArr.map(p => p.replace(/^[0-9]+$/, 'id')); let pathStr: string = req.method.toLocaleLowerCase() + '_' + partArr.join('/'); if (pathStr.charAt(pathStr.length - 1) === '/') { pathStr = pathStr.substring(0, pathStr.length - 1); } return pathStr; }
function parseURL(URL) { if (typeof URL === 'string') { return url.parse(URL); } return undefined; }
_(normalizeRoutes(routes)) // Map redirects to upstreams .map(route => getUpstream(route, normalizeRoutes(routes))) // Remove blank entries .compact() // Parse to lando things .map(route => _.merge({}, url.parse(route.key), {service: route.upstream.split(':')[0]})) // Filter unsupported upstreams .filter(route => _.includes(_.map(supported, 'name'), route.service)) // Merge in port data .map(route => _.merge({}, route, _.find(supported, {name: route.service}))) // Add port to data .map(route => ({service: route.service, config: getProxyMiddlewares(route)})) // Group by service .groupBy('service') // Map to lando proxy config .map((entries, service) => ([service, _.map(entries, 'config')])) // objectify .fromPairs() // Return .value()
use(request: Request, response: Response, next: () => void) { const req: any = request; const res: any = response; const pathname = url.parse(req.originalUrl).pathname; const trustArr = [ `${APIPrefix}/common/oss/callback`, ]; if (trustArr.indexOf(pathname) >= 0) { next(); return; } csrfProtection(req, res, next); }
resolve (req, res, buffer, callback) { let urlinfo = url.parse(req.url, true); let pathname = urlinfo.pathname; if (this.serviceName && pathname.indexOf(this.serviceName) !== 1) { let e = new Error(`Local Service Not Loaded: ${pathname}`); e.statusCode = 404; return callback(e); } else { pathname = pathname.substr(1 + this.serviceName.length); } let definition; try { definition = this.findDefinition(this.definitions, pathname); } catch (e) { e.statusCode = 404; return callback(e); } return callback(null, definition, {}, buffer); }
const urlBaseName = (urlStr: string) => { const pathname = url.parse(urlStr).pathname; const pathArr = pathname.split('/'); return pathArr[pathArr.length - 1]; }
// (publicKey -> cert) cache function verifyPublicKeyUrl(publicKeyUrl) { const parsedUrl = url.parse(publicKeyUrl); if (parsedUrl.protocol !== 'https:') { return false; } const hostnameParts = parsedUrl.hostname.split('.'); const length = hostnameParts.length; const domainParts = hostnameParts.slice(length - 2, length); const domain = domainParts.join('.'); return domain === 'apple.com'; }
function parseURL(URL) { if (typeof URL === 'string') { return url.parse(URL); } return undefined; }
// We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. // Webpack needs to know it to put the right <script> hrefs into HTML even in // single-page apps that may serve index.html for nested URLs like /todos/42. // We can't use a relative path in HTML because we don't want to load something // like /todos/42/static/js/bundle.7289d.js. We have to know the root. function getServedPath(appPackageJson) { const publicUrl = getPublicUrl(appPackageJson); const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); return ensureSlash(servedUrl, true); }
// We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. // Webpack needs to know it to put the right <script> hrefs into HTML even in // single-page apps that may serve index.html for nested URLs like /todos/42. // We can't use a relative path in HTML because we don't want to load something // like /todos/42/static/js/bundle.7289d.js. We have to know the root. function getServedPath(appPackageJson) { const publicUrl = getPublicUrl(appPackageJson); const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); return ensureSlash(servedUrl, true); }
// We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. // Webpack needs to know it to put the right <script> hrefs into HTML even in // single-page apps that may serve index.html for nested URLs like /todos/42. // We can't use a relative path in HTML because we don't want to load something // like /todos/42/static/js/bundle.7289d.js. We have to know the root. function getServedPath(appPackageJson) { const publicUrl = getPublicUrl(appPackageJson); const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); return ensureSlash(servedUrl, true); }