How to use resolveUrl method in wpt

Best JavaScript code snippet using wpt

server.js

Source:server.js Github

copy

Full Screen

1// http://127.0.0.1:90012// http://localhost:90013const fs = require('fs');4const path = require('path');5const url = require('url');6var httpServer = require('http');7const ioServer = require('socket.io');8const RTCMultiConnectionServer = require('rtcmulticonnection-server');9var PORT = 9001;10var isUseHTTPs = false;11const jsonPath = {12 config: 'config.json',13 logs: 'logs.json'14};15const BASH_COLORS_HELPER = RTCMultiConnectionServer.BASH_COLORS_HELPER;16const getValuesFromConfigJson = RTCMultiConnectionServer.getValuesFromConfigJson;17const getBashParameters = RTCMultiConnectionServer.getBashParameters;18const resolveURL = RTCMultiConnectionServer.resolveURL;19var config = getValuesFromConfigJson(jsonPath);20config = getBashParameters(config, BASH_COLORS_HELPER);21// if user didn't modifed "PORT" object22// then read value from "config.json"23if(PORT === 9001) {24 PORT = config.port;25}26if(isUseHTTPs === false) {27 isUseHTTPs = config.isUseHTTPs;28}29function serverHandler(request, response) {30 // to make sure we always get valid info from json file31 // even if external codes are overriding it32 config = getValuesFromConfigJson(jsonPath);33 config = getBashParameters(config, BASH_COLORS_HELPER);34 // HTTP_GET handling code goes below35 try {36 var uri, filename;37 try {38 if (!config.dirPath || !config.dirPath.length) {39 config.dirPath = null;40 }41 uri = url.parse(request.url).pathname;42 filename = path.join(config.dirPath ? resolveURL(config.dirPath) : process.cwd(), uri);43 } catch (e) {44 pushLogs(config, 'url.parse', e);45 }46 filename = (filename || '').toString();47 if (request.method !== 'GET' || uri.indexOf('..') !== -1) {48 try {49 response.writeHead(401, {50 'Content-Type': 'text/plain'51 });52 response.write('401 Unauthorized: ' + path.join('/', uri) + '\n');53 response.end();54 return;55 } catch (e) {56 pushLogs(config, '!GET or ..', e);57 }58 }59 if(filename.indexOf(resolveURL('/admin/')) !== -1 && config.enableAdmin !== true) {60 try {61 response.writeHead(401, {62 'Content-Type': 'text/plain'63 });64 response.write('401 Unauthorized: ' + path.join('/', uri) + '\n');65 response.end();66 return;67 } catch (e) {68 pushLogs(config, '!GET or ..', e);69 }70 return;71 }72 var matched = false;73 ['/demos/', '/dev/', '/dist/', '/socket.io/', '/node_modules/canvas-designer/', '/admin/'].forEach(function(item) {74 if (filename.indexOf(resolveURL(item)) !== -1) {75 matched = true;76 }77 });78 // files from node_modules79 ['RecordRTC.js', 'FileBufferReader.js', 'getStats.js', 'getScreenId.js', 'adapter.js', 'MultiStreamsMixer.js'].forEach(function(item) {80 if (filename.indexOf(resolveURL('/node_modules/')) !== -1 && filename.indexOf(resolveURL(item)) !== -1) {81 matched = true;82 }83 });84 if (filename.search(/.js|.json/g) !== -1 && !matched) {85 try {86 response.writeHead(404, {87 'Content-Type': 'text/plain'88 });89 response.write('404 Not Found: ' + path.join('/', uri) + '\n');90 response.end();91 return;92 } catch (e) {93 pushLogs(config, '404 Not Found', e);94 }95 }96 ['Video-Broadcasting', 'Screen-Sharing', 'Switch-Cameras'].forEach(function(fname) {97 try {98 if (filename.indexOf(fname + '.html') !== -1) {99 filename = filename.replace(fname + '.html', fname.toLowerCase() + '.html');100 }101 } catch (e) {102 pushLogs(config, 'forEach', e);103 }104 });105 var stats;106 try {107 stats = fs.lstatSync(filename);108 if (filename.search(/demos/g) === -1 && filename.search(/admin/g) === -1 && stats.isDirectory() && config.homePage === '/demos/index.html') {109 if (response.redirect) {110 response.redirect('/demos/');111 } else {112 response.writeHead(301, {113 'Location': '/demos/'114 });115 }116 response.end();117 return;118 }119 } catch (e) {120 response.writeHead(404, {121 'Content-Type': 'text/plain'122 });123 response.write('404 Not Found: ' + path.join('/', uri) + '\n');124 response.end();125 return;126 }127 try {128 if (fs.statSync(filename).isDirectory()) {129 response.writeHead(404, {130 'Content-Type': 'text/html'131 });132 if (filename.indexOf(resolveURL('/demos/MultiRTC/')) !== -1) {133 filename = filename.replace(resolveURL('/demos/MultiRTC/'), '');134 filename += resolveURL('/demos/MultiRTC/index.html');135 } else if (filename.indexOf(resolveURL('/admin/')) !== -1) {136 filename = filename.replace(resolveURL('/admin/'), '');137 filename += resolveURL('/admin/index.html');138 } else if (filename.indexOf(resolveURL('/demos/dashboard/')) !== -1) {139 filename = filename.replace(resolveURL('/demos/dashboard/'), '');140 filename += resolveURL('/demos/dashboard/index.html');141 } else if (filename.indexOf(resolveURL('/demos/video-conference/')) !== -1) {142 filename = filename.replace(resolveURL('/demos/video-conference/'), '');143 filename += resolveURL('/demos/video-conference/index.html');144 } else if (filename.indexOf(resolveURL('/demos')) !== -1) {145 filename = filename.replace(resolveURL('/demos/'), '');146 filename = filename.replace(resolveURL('/demos'), '');147 filename += resolveURL('/demos/index.html');148 } else {149 filename += resolveURL(config.homePage);150 }151 }152 } catch (e) {153 pushLogs(config, 'statSync.isDirectory', e);154 }155 var contentType = 'text/plain';156 if (filename.toLowerCase().indexOf('.html') !== -1) {157 contentType = 'text/html';158 }159 if (filename.toLowerCase().indexOf('.css') !== -1) {160 contentType = 'text/css';161 }162 if (filename.toLowerCase().indexOf('.png') !== -1) {163 contentType = 'image/png';164 }165 fs.readFile(filename, 'binary', function(err, file) {166 if (err) {167 response.writeHead(500, {168 'Content-Type': 'text/plain'169 });170 response.write('404 Not Found: ' + path.join('/', uri) + '\n');171 response.end();172 return;173 }174 try {175 file = file.replace('connection.socketURL = \'/\';', 'connection.socketURL = \'' + config.socketURL + '\';');176 } catch (e) {}177 response.writeHead(200, {178 'Content-Type': contentType179 });180 response.write(file, 'binary');181 response.end();182 });183 } catch (e) {184 pushLogs(config, 'Unexpected', e);185 response.writeHead(404, {186 'Content-Type': 'text/plain'187 });188 response.write('404 Not Found: Unexpected error.\n' + e.message + '\n\n' + e.stack);189 response.end();190 }191}192var httpApp;193if (isUseHTTPs) {194 httpServer = require('https');195 // See how to use a valid certificate:196 // https://github.com/muaz-khan/WebRTC-Experiment/issues/62197 var options = {198 key: null,199 cert: null,200 ca: null201 };202 var pfx = false;203 if (!fs.existsSync(config.sslKey)) {204 console.log(BASH_COLORS_HELPER.getRedFG(), 'sslKey:\t ' + config.sslKey + ' does not exist.');205 } else {206 pfx = config.sslKey.indexOf('.pfx') !== -1;207 options.key = fs.readFileSync(config.sslKey);208 }209 if (!fs.existsSync(config.sslCert)) {210 console.log(BASH_COLORS_HELPER.getRedFG(), 'sslCert:\t ' + config.sslCert + ' does not exist.');211 } else {212 options.cert = fs.readFileSync(config.sslCert);213 }214 if (config.sslCabundle) {215 if (!fs.existsSync(config.sslCabundle)) {216 console.log(BASH_COLORS_HELPER.getRedFG(), 'sslCabundle:\t ' + config.sslCabundle + ' does not exist.');217 }218 options.ca = fs.readFileSync(config.sslCabundle);219 }220 if (pfx === true) {221 options = {222 pfx: sslKey223 };224 }225 httpApp = httpServer.createServer(options, serverHandler);226} else {227 httpApp = httpServer.createServer(serverHandler);228}229RTCMultiConnectionServer.beforeHttpListen(httpApp, config);230httpApp = httpApp.listen(process.env.PORT || PORT, process.env.IP || "0.0.0.0", function() {231 RTCMultiConnectionServer.afterHttpListen(httpApp, config);232});233// --------------------------234// socket.io codes goes below235ioServer(httpApp).on('connection', function(socket) {236 RTCMultiConnectionServer.addSocket(socket, config);237 // ----------------------238 // below code is optional239 const params = socket.handshake.query;240 if (!params.socketCustomEvent) {241 params.socketCustomEvent = 'custom-message';242 }243 socket.on(params.socketCustomEvent, function(message) {244 socket.broadcast.emit(params.socketCustomEvent, message);245 });...

Full Screen

Full Screen

resolve-url.js

Source:resolve-url.js Github

copy

Full Screen

...6test("resolveUrl", function(t) {7 t.plan(7)8 t.equal(typeof resolveUrl, "function", "is a function")9 t.equal(10 resolveUrl("https://example.com/"),11 "https://example.com/"12 )13 var loc = "https://example.com/articles/resolving-urls/edit"14 t.equal(15 resolveUrl(loc, "remove"),16 "https://example.com/articles/resolving-urls/remove"17 )18 t.equal(19 resolveUrl(loc, "/static/scripts/app.js"),20 "https://example.com/static/scripts/app.js"21 )22 t.equal(23 resolveUrl(loc, "/static/scripts/app.js", "../source-maps/app.js.map"),24 "https://example.com/static/source-maps/app.js.map"25 )26 t.equal(27 resolveUrl(loc, "/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee"),28 "https://example.com/static/coffee/app.coffee"29 )30 t.equal(31 resolveUrl(loc, "//cdn.example.com/jquery.js"),32 "https://cdn.example.com/jquery.js"33 )34})35test("edge cases", function(t) {36 t.plan(4)37 t["throws"](resolveUrl, /at least one argument/, "throws with no arguments")38 var accidentallyUndefined39 var result40 t.doesNotThrow(41 function() { result = resolveUrl(accidentallyUndefined) },42 "undefined is still an argument"43 )44 t.ok(result.match(/\/undefined$/), "undefined is stringified")45 t.equal(46 resolveUrl("http://foo.org/test", undefined, {}, ["a/b"], null),47 "http://foo.org/a/null",48 "arguments are stringified"49 )...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10wpt.runTest('www.google.com', function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17wpt.getTestStatus('140202_5Z_6R', function(err, data) {18 if (err) {19 console.log(err);20 } else {21 console.log(data);22 }23});24wpt.getTestResults('140202_5Z_6R', function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31wpt.getTestResults('140202_5Z_6R', {breakdown: 1}, function(err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 }37});38wpt.getTestResults('140202_5Z_6R', {requests: 1}, function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45wpt.getTestResults('140202_5Z_6R', {requests: 1, breakdown: 1}, function(err, data) {46 if (err) {47 console.log(err);48 } else {49 console.log(data);50 }51});52wpt.getTestResults('140202_5Z_6R', {requests: 1, breakdown: 1, pagespeed: 1}, function(err, data) {53 if (err) {54 console.log(err);55 } else {56 console.log(data);57 }58});59wpt.getTestResults('140202_5Z_6R', {requests: 1, breakdown: 1, pagespeed: 1, medianMetric: 'TTFB'}, function(err, data) {60 if (err) {61 console.log(err);62 } else {63 console.log(data);64 }65});66wpt.getTestResults('140202_5Z_6R', {requests: 1, breakdown: 1, pages

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var options = {3};4wptools.resolveUrl(url, options, function(err, page) {5 if (err) {6 console.log(err);7 } else {8 console.log(page);9 }10});11var wptools = require('wptools');12var page = wptools('Barack_Obama');13page.get(function(err, page) {14 if (err) {15 console.log(err);16 } else {17 console.log(pag

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var url = wptools.resolveUrl('en', 'Paris');3console.log(url);4var wptools = require('wptools');5var url = wptools.resolveUrl('en', 'Paris', 'wikidata');6console.log(url);7var wptools = require('wptools');8var url = wptools.resolveUrl('en', 'Paris', 'wikidata', 'property');9console.log(url);10var wptools = require('wptools');11var url = wptools.resolveUrl('en', 'Paris', 'wikidata', 'property', 'P31');12console.log(url);13var wptools = require('wptools');14var url = wptools.resolveUrl('en', 'Paris', 'wikidata', 'entity');15console.log(url);16var wptools = require('wptools');17var url = wptools.resolveUrl('en', 'Paris', 'wikidata', 'entity', 'Q90');18console.log(url);19var wptools = require('wptools');20var url = wptools.resolveUrl('en', 'Paris', 'wikidata', 'entity', 'Q90', 'sitelink', 'enwiki');21console.log(url);22var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2console.log(url);3var wptoolkit = require('wptoolkit');4console.log(url);5var wptoolkit = require('wptoolkit');6console.log(url);7var wptoolkit = require('wptoolkit');8console.log(url);9var wptoolkit = require('wptoolkit');10console.log(url);11var wptoolkit = require('wptoolkit');12console.log(url);13var wptoolkit = require('wptoolkit');14console.log(url);15var wptoolkit = require('wptoolkit');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var wptoolkit = require('wptoolkit');3var wptoolkit = require('wptoolkit');4var wptoolkit = require('wptoolkit');5var wptoolkit = require('wptoolkit');6var wptoolkit = require('wptoolkit');7var wptoolkit = require('wptoolkit');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful