HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/rest/node_modules/machinepack-urls/machines/parse.js
module.exports = {


  friendlyName: 'Parse URL',


  description: 'Parse metadata from a URL.',


  sync: true,


  cacheable: true,


  extendedDescription: '',


  inputs: {

    url: {
      description: 'The URL to parse',
      example: 'http://www.example.com/search',
      required: true
    }

  },


  defaultExit: 'success',


  exits: {

    error: {
      description: 'Unexpected error occurred.'
    },

    success: {
      description: 'Done.',
      example: {
        protocol: 'redis:',
        auth: '',
        port: 80,
        hostname: 'google.com',
        hash: '',
        search: '',
        path: '/',
        // slashes: true,
        // host: 'google.com',
        // query: {},
        // pathname: '/',
        // href: 'http://google.com/'
      }
    }

  },


  fn: function(inputs, exits) {

    var Url = require('url');
    // var sanitizeUrl = require('machine').build(require('./sanitize'));

    // var sanitizedUrl;
    // try {
    //   sanitizedUrl = sanitizeUrl({url: inputs.url}).execSync();
    // }
    // catch (e) {
    //   if (e.exit === 'invalid') return exits.invalid();
    //   return exits.error(e);
    // }

    var parsedUrl = Url.parse(inputs.url);

    // Attempt to infer port if it doesn't exist
    if (!parsedUrl.port) {
      if (parsedUrl.protocol === 'https:') {
        parsedUrl.port = 443;
      }
      else {
        parsedUrl.port = 80;
      }
    }

    return exits.success(parsedUrl);
  },

};