xref: /third_party/node/test/fixtures/es-module-loaders/http-loader.mjs
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/fixtures/es-module-loaders/
11cb0ef41Sopenharmony_ciimport { get } from 'http';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciexport function load(url, context, nextLoad) {
41cb0ef41Sopenharmony_ci  if (url.startsWith('http://')) {
51cb0ef41Sopenharmony_ci    return new Promise((resolve, reject) => {
61cb0ef41Sopenharmony_ci      get(url, (rsp) => {
71cb0ef41Sopenharmony_ci        let data = '';
81cb0ef41Sopenharmony_ci        rsp.on('data', (chunk) => data += chunk);
91cb0ef41Sopenharmony_ci        rsp.on('end', () => {
101cb0ef41Sopenharmony_ci          resolve({
111cb0ef41Sopenharmony_ci            format: 'module',
121cb0ef41Sopenharmony_ci            shortCircuit: true,
131cb0ef41Sopenharmony_ci            source: data,
141cb0ef41Sopenharmony_ci          });
151cb0ef41Sopenharmony_ci        });
161cb0ef41Sopenharmony_ci      })
171cb0ef41Sopenharmony_ci      .on('error', reject);
181cb0ef41Sopenharmony_ci    });
191cb0ef41Sopenharmony_ci  }
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  return nextLoad(url);
221cb0ef41Sopenharmony_ci}
23

Indexes created Thu Nov 07 10:32:03 CST 2024