zoukankan      html  css  js  c++  java
  • Ionic Framework

    This is a quick hacky way to get the ionic start [appName] command working from behind a proxy. I ran into the problem going through the steps on the Getting Started with Ionic page. For some reason the ionic cmd doesn't use the npm proxy or git proxy settings.

    I did this on a Windows 7 machine but the same should work in another OS just the file locations will be different.

    1. Add the proxy url to request.js located at 'C:Users[username]AppDataRoaming pm ode_modulesionic ode_modules equest equest.js'. Here's the update including the lines just before and after so you can find where to put it.

      if (self.strictSSL === false) {
        self.rejectUnauthorized = false
      }
    
      // hack to add proxy
      self.proxy = 'http://10.68.0.5:8080';
    
      if (self.proxy) {
        if (typeof self.proxy == 'string') self.proxy = url.parse(self.proxy)
    
        // do the HTTP CONNECT dance using koichik/node-tunnel
        if (http.globalAgent && self.uri.protocol === "https:") {
          var tunnelFn = self.proxy.protocol === "http:"
                       ? tunnel.httpsOverHttp : tunnel.httpsOverHttps
    
          var tunnelOptions = { proxy: { host: self.proxy.hostname
                                       , port: +self.proxy.port
                                       , proxyAuth: self.proxy.auth
                                       , headers: { Host: self.uri.hostname + ':' +
                                            (self.uri.port || self.uri.protocol === 'https:' ? 443 : 80) }}
                              , rejectUnauthorized: self.rejectUnauthorized
                              , ca: this.ca }
    
          self.agent = tunnelFn(tunnelOptions)
          self.tunnel = true
        }
      }
    

    2. Add the proxy url to registry.js located at 'C:Users[username]AppDataRoaming pm ode_modulescordova ode_modulesplugmansrc egistry egistry.js', again I've included the lines around the hack so you can find where to put it.

      headers.accept = "application/json"
    
      headers["user-agent"] = settings['user-agent'] ||
                              'node/' + process.version
    
      // hack to add proxy
      var p = settings.proxy || 'http://10.68.0.5:8080'
      var sp = settings['https-proxy'] || p
      opts.proxy = remote.protocol === "https:" ? sp : p
    
      // figure out wth 'what' is
      if (what) {
        if (Buffer.isBuffer(what) || typeof what === "string") {
          opts.body = what
          headers["content-type"] = "application/json"
          headers["content-length"] = Buffer.byteLength(what)
        } else {
          opts.json = what
        }
      }

    That's it! You should now be able to create ionic apps without an issue.

    Just in case people are searching for how to do this by googling the command line errors, I've included them below.

    First error

    D:Projects>ionic start myApp tabs
    Running start task...
    Creating Ionic app in folder D:ProjectsmyApp based on tabs project
    
    DOWNLOADING: https://github.com/driftyco/ionic-app-base/archive/master.zip
    
    TypeError: Cannot read property 'statusCode' of undefined
        at Request._callback (C:UserswatmorjAppDataRoaming
    pm
    ode_modulesioniclibionic.js:241:13)
        at self.callback (C:UserswatmorjAppDataRoaming
    pm
    ode_modulesionic
    ode_modules
    equest
    equest.js:129:22)
        at Request.EventEmitter.emit (events.js:95:17)
        at ClientRequest.self.clientErrorHandler (C:UserswatmorjAppDataRoaming
    pm
    ode_modulesionic
    ode_modules
    equest
    equest.js:239:10)
        at ClientRequest.EventEmitter.emit (events.js:95:17)
        at CleartextStream.socketErrorListener (http.js:1547:9)
        at CleartextStream.EventEmitter.emit (events.js:95:17)
        at Socket.onerror (tls.js:1445:17)
        at Socket.EventEmitter.emit (events.js:117:20)
        at net.js:441:14

    Second error

    Initializing cordova project.
    Fetching plugin "org.apache.cordova.device" via plugin registry
    Error: Failed to fetch package information for org.apache.cordova.device
        at C:UserswatmorjAppDataRoaming
    pm
    ode_modulescordova
    ode_modulesplugmansrc
    egistry
    egistry.js:32:20
        at Request.cb [as _callback] (C:UserswatmorjAppDataRoaming
    pm
    ode_modulescordova
    ode_modulesplugmansrc
    egistry
    egistry.js:251:9)
        at self.callback (C:UserswatmorjAppDataRoaming
    pm
    ode_modulescordova
    ode_modulesplugman
    ode_modules
    equestindex.js:148:22)
        at Request.EventEmitter.emit (events.js:117:20)
        at ClientRequest.self.clientErrorHandler (C:UserswatmorjAppDataRoaming
    pm
    ode_modulescordova
    ode_modulesplugman
    ode_modules
    equestindex.js:257:10)
        at ClientRequest.EventEmitter.emit (events.js:95:17)
        at Socket.socketErrorListener (http.js:1547:9)
        at Socket.EventEmitter.emit (events.js:95:17)
        at net.js:441:14
        at process._tickCallback (node.js:415:13)
    ERROR: Unable to add plugins. Perhaps your version of Cordova is too old. Try updating (npm install -g cordova), removing this project folder, and trying again.
    Exiting.
  • 相关阅读:
    React class & function component 的区别
    Webpack 4 + React + Typescript 搭建启动模版
    JavaScript的数据类型及其检测
    react SyntheticEvent 合成事件机制
    数组的排序
    Ajax 和 Ajax的封装
    go 结构的方法总结
    go 结构的方法2
    go struct 的方法1
    go 函数闭包
  • 原文地址:https://www.cnblogs.com/dhcn/p/7115412.html
Copyright © 2011-2022 走看看