vuejs can't set new data - laravel

getSlideShow: function () {
this.$http.post(api||web).then((response) => {
// console.log(response.data);` return path success
if (response.data[0]) {
console.log(response.data[0].file); // check link ok
this.image_slide_1 = path + response.data[0].file;
}
if (response.data[1]) {
console.log(this.image_slide_1); data changed
this.image_slide_2 = path + response.data[1].file;
}
}
}
<img :src="image_slide_1"
if me set data before request
`this.data = ... `
`this.$http.post()`
// image show
but set data in request http sound not work
and where login set data before request still work (even set data after request), but logout that not work
i have lost quite some time and to no avail, any suggestions to modify it

Related

Firefox extension proxy

I am trying to create a Firefox extension to block search terms on school computers. I'd like to prohibit a list of keywords, but the blocking doesn't seem to be working.
I found an example through a plugin gallery here:
https://github.com/mdn/webextensions-examples/blob/master/proxy-blocker/background/proxy-handler.js
This plugin listens to blocked hosts, and then basically returns localhost. I'd like to do the same, but when search terms are added in. I used the code in the example above as a starting point.
Here is the code I have so far:
// Initialize the list of blocked hosts
let blockedHosts = ["www.duckduckgo.com", "www.google.com"];
let blockedTerms = ["games", "minecraft", "legos"];
// Set the default list on installation.
browser.runtime.onInstalled.addListener(details => {
browser.storage.local.set({
blockedHosts: blockedHosts
});
});
// Get the stored list
browser.storage.local.get(data => {
if (data.blockedHosts) {
blockedHosts = data.blockedHosts;
}
});
// Listen for changes in the blocked list
browser.storage.onChanged.addListener(changeData => {
blockedHosts = changeData.blockedHosts.newValue;
});
// Managed the proxy
// Listen for a request to open a webpage
browser.proxy.onRequest.addListener(handleProxyRequest, {urls: ["<all_urls>"]});
function handleProxyRequest(requestInfo) {
let urlToCheck = new URL(requestInfo.documentUrl)
let searchString = urlToCheck.search;
const url = new URL(requestInfo.url);
let found;
blockedTerms.map((term) =>{
if(searchString.search(term) != -1){
found = true
}
})
if ( blockedHosts.indexOf(url.hostname) != -1 & found) {
return {type: "https", host: "127.0.0.1", port: 65535};
}
// Return instructions to open the requested webpage
return {type: "direct"};
}
// Log any errors from the proxy script
browser.proxy.onError.addListener(error => {
console.error(`Proxy error: ${error.message}`);
});
The URL that the browser creates is https://duckduckgo.com/?t=ffab&q=games&ia=web for example. I can determine that the term "games" was found, and that it was found in a duck duck go search, but the proxy wont work and the browser wont stop the user from going to the page.
Any help would be appreciated!
To start with, in a school environment, I suppose they have to use school net connection. It would be a lot easier to block at the main internet connection instead of creating and installing an addon on each computer (that might be altered or bypassed with another browser).
However, to answer your question, the following would be one (simpler) way of doing that using webRequest.onBeforeRequest:
// add a listener for web requests
browser.webRequest.onBeforeRequest.addListener(process, {
urls: ['*://*/*']
},
['blocking']
);
function process(e) {
// e.url is the target url
// no need for storage as the filter-list is hard-coded
const blockedHosts = ['www.duckduckgo.com', 'www.google.com'];
const blockedTerms = ['games', 'minecraft', 'legos'];
const hostRegExp = new RegExp(`^https?://(${blockedHosts.join('|')})/`, 'i');
const termRegExp = new RegExp(`(${blockedTerms.join('|')})`, 'i');
// if matches above criteria, redirect to 127.0.0.1
if (hostRegExp.test(e.url) && termRegExp.test(e.url)) {
return {redirectUrl: 'https://127.0.0.1:65535/'};
}
}

How would you grab old responses in cypress?

I have been trying to grab an old response to assert it has a certain response.
The issue is that the same call is posted at the same time and I can only grab the second response.
I was just wondering if there was a way to grab both responses so I can read each body to make sure the correct posts are made
I have used the following
public assertMixPanelCall(call: string): void {
cy.intercept('POST', 'https://api-js.mixpanel.com/track/*', (req) => {
if (atob(req.body.replace('data=', '')).includes(`"event": "${call}"`)) {
req.alias = 'correctBody'
}
});
cy.wait('#correctBody');
}
So the response I get is the last response,
But I want to grab the penultimate response
I'm not seeing the complete picture, but I think you can use this pattern Intercepting a response
let responseCount = 0;
cy.intercept('POST', 'https://api-js.mixpanel.com/track/*', (req) => {
if (atob(req.body.replace('data=', '')).includes(`"event": "${call}"`)) {
req.continue((res) => {
responseCount++;
if (responseCount === 1) {
req.alias = 'penultimate'
}
if (responseCount === 2) {
req.alias = 'final'
}
})
}
});
cy.wait('#penultimate')
Not sure if dynamic aliasing works on a per-response basis.
There's also an undocumented alias suffix that lets you access the nth response
cy.wait('#correctBody'); // must wait first
cy.get('#correctBody.1'); // then get to access response history
// - not sure if you need #correctBody.0 or #correctBody.1
But I can't see why cy.wait('#correctBody') doesn't catch the first response, generally you need to issue the wait twice to get both responses. Anyway, there's some things to try out here.
So I found the solution
From wherever I want to start capturing
cy.intercept('POST', 'https://api-js.mixpanel.com/track/*').as('call');
generate array based on the number of calls previously I wish to check
const genArr = Array.from({length:noOfCalls},(v,k)=>k+1);
const calls = [];
cy.wrap(genArr).each(() => {
calls.push(`#${call}`)
})
make the call based on the amount of times I wish to post the response
cy.wait(calls).then(differentRequests => {
differentRequests.forEach(differentRequest => {
if(atob(differentRequest.request.body.replace('data=','')).includes(call)) {
pass = true
}
});
expect(pass).to.be.true
});
}
Got the solution from here
https://medium.com/slido-dev-blog/cypress-io-is-pretty-amazing-and-if-you-havent-used-it-yet-and-need-a-jump-start-i-recommend-my-66ee6ac5f8d9

URLS Redirects with Cypress automation

I passed 100+ URLs path(legacy) in the scenario outlines and i want to hit each one of them and to redirect to a new path(new).
I passed a code like below;
function createNewUrlFromLegacy(legacyPageUrl) {
const urlPath = legacyPageUrl.split('/');
let newUrl;
if (urlPath.length == 7) {
newUrl = 'new-homes/' + urlPath[5];
} else {
newUrl = 'new-homes/' + urlPath[0];
}
return newUrl
}
I passed this following in my stepDef file
const expectedUrl = createNewUrlFromLegacy(legacyUrl);
cy.url().should('include', expectedUrl);
And it run successfully.
But i want to use response code 301 as an assertion instead relying on expectedUrl only.
How can i do this pls?.
I have managed to get it working using the following steps;
First visit the legacy url and then set followRedirects: false using alias.
cy.visit(legacyUrl);
cy.request({url: legacyUrl, followRedirect: false}).as('response');`
cy.get('#response').its('status').should('eq', 301); --> Assert Response code is 301
cy.get('#response').its('redirectedToUrl').should('contain', expectedUrl); -->Assert expected URL is displayed.

How to Facebook Connect on server side via Ajax using Node, Express and Connect-auth

I've got a piece of code that look like this.
app.get('/auth/facebook', function( request, response ) {
if( request.session.user ){
response.render( 'index.jade' );
} else {
request.authenticate(['facebook'], function(error, authenticated) {
if( authenticated ) {
request.session.user = request.getAuthDetails().user;
response.writeHead(303, { 'Location': "/auth/facebook" });
}
});
}
});
If there is a user in session it will render the page, if not it will get a user from Facebook and store that in a session variable and reload the page... and render it. It works perfectly fine. But I want to trigger that piece of code via AJAX and do something like this:
app.get('/auth/facebook', function( request, response ) {
response.contentType('application/json');
if( request.session.user ){
response.send(JSON.stringify({'authenticated':true}));
} else {
request.authenticate(['facebook'], function(error, authenticated) {
if( authenticated ) {
request.session.user = request.getAuthDetails().user;
response.writeHead(303, { 'Location': "/auth/facebook" });
} else {
response.send(JSON.stringify({'authenticated':false}));
}
});
}
});
But that doesn't work. It says "Can't use mutable header APIs after sent" and puts it self in an endless loop saying "Can't render headers after they are sent to the client." over and over again.
Am I going about this the wrong way? I want my server code to connect with Facebook without the need of a page reload.

Zipcode to city/state look-up XML file?

Trying to find an XML file I can use in lieu of a look-up database table until we get our web hosting switched over to the right DB.
Can anyone refer me to an XML file with elements whose children have zipcodes, states, and cities? E.g.:
<zip code="98117">
<state>WA</state>
<city>Seattle</state>
</zip>
Or
<entry>
<zip>98117</zip>
<state>WA</state>
<city>Seattle</city>
</entry>
I'll be using LINQ in C# to query this data.
Check out this one, it provides several different free ones.
https://stackoverflow.com/questions/24471/zip-code-database
There is a free zip code database located at:
http://www.populardata.com
I believe its a .CSV file but you could convert it to a XML file quite easily.
Here is code to do city.state autofill based on a zipcode entered.
<script type="text/javascript">//<![CDATA[
$(function() {
// IMPORTANT: Fill in your client key
var clientKey = "js-9qZHzu2Flc59Eq5rx10JdKERovBlJp3TQ3ApyC4TOa3tA8U7aVRnFwf41RpLgtE7";
var cache = {};
var container = $("#example1");
var errorDiv = container.find("div.text-error");
/** Handle successful response */
function handleResp(data)
{
// Check for error
if (data.error_msg)
errorDiv.text(data.error_msg);
else if ("city" in data)
{
// Set city and state
container.find("input[name='city']").val(data.city);
container.find("input[name='state']").val(data.state);
}
}
// Set up event handlers
container.find("input[name='zipcode']").on("keyup change", function() {
// Get zip code
var zipcode = $(this).val().substring(0, 5);
if (zipcode.length == 5 && /^[0-9]+$/.test(zipcode))
{
// Clear error
errorDiv.empty();
// Check cache
if (zipcode in cache)
{
handleResp(cache[zipcode]);
}
else
{
// Build url
var url = "http://www.zipcodeapi.com/rest/"+clientKey+"/info.json/" + zipcode + "/radians";
// Make AJAX request
$.ajax({
"url": url,
"dataType": "json"
}).done(function(data) {
handleResp(data);
// Store in cache
cache[zipcode] = data;
}).fail(function(data) {
if (data.responseText && (json = $.parseJSON(data.responseText)))
{
// Store in cache
cache[zipcode] = json;
// Check for error
if (json.error_msg)
errorDiv.text(json.error_msg);
}
else
errorDiv.text('Request failed.');
});
}
}
}).trigger("change");
});
//]]>
Here is the API - http://www.zipcodeapi.com/Examples#example1.
You can request the content in XML via To get the data back directly in XML you can use .xml in the format in the request.
https://www.zipcodeapi.com/rest/RbdapNcxbjoCvfCv4N5iwB3L4beZg017bfiB2u9eOxQkMtQQgV9NxdyCoNCENDMZ/info.xml/90210/degrees
Will respond with
<response>
<zip_code>90210</zip_code>
<lat>34.100501</lat>
<lng>-118.414908</lng>
<city>Beverly Hills</city>
<state>CA</state>
<timezone>
<timezone_identifier>America/Los_Angeles</timezone_identifier>
<timezone_abbr>PDT</timezone_abbr>
<utc_offset_sec>-25200</utc_offset_sec>
<is_dst>T</is_dst>
</timezone>
<acceptable_city_names/>
</response>
Api docs are at https://www.zipcodeapi.com/API

Resources