{"version":3,"sources":["jsdelivr-header.js","/npm/knightjs@0.0.1/lib/create-server.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,KAAO,QAAQ,QACf,GAAK,QAAQ,MACb,IAAM,QAAQ,OACd,KAAO,QAAQ,QACf,IAAM,QAAQ,OACd,KAAO,QAAQ,UAErB,OAAO,QAAU,SAAU,EAAM,GAC7B,MAAM,EAAS,KAAK,cAAa,CAAC,EAAK,KAEnC,IAAI,EAAW,IADG,IAAI,MAAM,EAAI,KACH,WAC7B,GAAG,OAAO,GAAU,IAChB,IAAK,EAED,OADA,EAAI,WAAa,IACV,EAAI,IAAI,QAAQ,gBAIvB,GAAG,SAAS,GAAU,gBACtB,GAAY,IAAI,KAIpB,GAAG,SAAS,GAAU,CAAC,EAAK,KACxB,GAAI,EACA,EAAI,WAAa,IACjB,EAAI,IAAI,2BAA2B,UAChC,CACH,EAAI,WAAa,IAEjB,MAAM,EAAM,KAAK,MAAM,GAAU,IAEjC,EAAI,UAAU,eAAgB,KAAK,IAAQ,cAC3C,EAAI,IAAI,EACZ,IACH,GACJ,IAGL,EAAO,OAAO,GAEd,EAAO,GAAG,aAAa,KACnB,QAAQ,IAAI,mBACZ,QAAQ,IAAI,gDAAgD,KAC5D,IAAI,oBAAoB,IAAM,GAEtC","file":"/npm/knightjs@0.0.1/lib/create-server.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/knightjs@0.0.1/lib/create-server.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const http = require('http')\nconst fs = require('fs')\nconst url = require('url')\nconst path = require('path')\nconst opn = require('opn')\nconst mime = require('./mime')\n\nmodule.exports = function (file, port) {\n    const server = http.createServer((req, res) => {\n        const parsedUrl = url.parse(req.url)\n        let pathname = `.${parsedUrl.pathname}`\n        fs.exists(pathname, exist => {\n            if (!exist) {\n                res.statusCode = 404\n                return res.end(`File ${pathname} not found.`)\n            }\n            \n            // if is a directory, then look for index.html\n            if (fs.statSync(pathname).isDirectory()) {\n                pathname += `/${file}`\n            }\n            \n            // read file from file system\n            fs.readFile(pathname, (err, data) => {\n                if (err) {\n                    res.statusCode = 500\n                    res.end(`Error getting the file: ${err}.`)\n                } else {\n                    res.statusCode = 200\n                    // based on the URL path, extract the file extention. e.g. .js, .doc, ...\n                    const ext = path.parse(pathname).ext\n                    // if the file is found, set Content-type and send data\n                    res.setHeader('Content-type', mime[ext] || 'text/plain')\n                    res.end(data)\n                }\n            })\n        })\n    })\n    \n    server.listen(port)\n    \n    server.on('listening', () => {\n        console.log(`Server created!`)\n        console.log(`open your browser and visit http://localhost:${port}`)\n        opn(`http://localhost:${port}`)\n    })\n}\n"]}