小编Yas*_*obi的帖子

Next Js自定义路线和SSR

我在next上使用apollo,最近我注意到自定义路由破坏了SSR。通常,如果您浏览页面,则阿波罗会缓存查询,而当您下次访问页面时,它将处理缓存中的所有内容。但是,对于自定义路由,永远不会使用缓存。

我还注意到,当我单击这些页面时,控制台中会闪烁一个错误。但是它很快消失了,我无法在这里复制它。

Server.js

// 
   server.get('/about-us', (req, res) => app.render(req, res, '/about'));


   server.get('/about', (req, res) => res.redirect(301, '/about-us'));
Run Code Online (Sandbox Code Playgroud)

菜单点击处理程序

const navigate = link => () => {
        Router.push(link);
    };
Run Code Online (Sandbox Code Playgroud)

菜单项

export const menu = [
    {
        name: 'Home',
        url: '/',
    },
    {
        name: 'Catalogs',
        url: '/catalogs',
    },
    {
        name: 'Shop',
        url: '/shop',
    },
    {
        name: 'Wholesale',
        url: '/wholesale',
    },
    {
        name: 'About Us',
        url: '/about-us',
        prefetch: true,
    },
    {
        name: 'Contact Us',
        url: '/contact-us',
        prefetch: true,
    },
];

Run Code Online (Sandbox Code Playgroud)

根据nextjs频谱的建议,我尝试在TopNav组件中预取自定义页面,但没有成功。

const prefetch …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express react-apollo next.js

14
推荐指数
1
解决办法
1964
查看次数

Wordpress Rest API反向代理

我正在尝试使用wordpress设置反向代理并排除几个路径.我的排除规则适用于admin,includes,.. etc,但它不适用于/ wp-json /.我怀疑是因为.htaccess.我需要wordpress来返回其余的api数据,因为我在gatsbyjs中使用它.

我花了一整天的时间试图解决这个问题.出于某种原因,我的setup/wp-json /返回404,它被代理到我网站的前端部分所在的netlify服务器.如果我删除所有代理规则wp-json的工作原理.

.htaccess包含默认的wordpress内容.

这是我的虚拟主机的pastebin:https: //pastebin.com/vFh6hCkN

<IfModule mod_ssl.c>
   <VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive …
Run Code Online (Sandbox Code Playgroud)

mod-proxy http-proxy wordpress-rest-api gatsby

8
推荐指数
1
解决办法
705
查看次数

用于ES6 Generator的hasNext()

我将如何为生成器实现hasNext()方法。我尝试了许多选项,例如将生成器添加为return语句并从闭包中屈服。获取第一个值将其打印出来,然后使用while等,但是它们都没有实际起作用。

我知道我可以使用诸如of或while之类的如何循环来自generator的JavaScript迭代器? 但仍然想知道是否可以添加hasNext()。

function *range(start,end){

    while(start < end){
        yield start; 
        start++
    }
}

let iterator = range(1,10); 

// so I can do something like this. 
while(iterator.hasNext()){
   console.log(iterator.next().value); 
}
Run Code Online (Sandbox Code Playgroud)

javascript iterator generator ecmascript-6

6
推荐指数
1
解决办法
8869
查看次数

覆盖 package.json 脚本 - NPM

有没有办法覆盖 package.json 脚本?我无法更改 package.json 因为它会为每个人更改它。即在我们的包中我们有

"script": {
    "dev": "yarn dev:build" 
}
Run Code Online (Sandbox Code Playgroud)

我想为此步骤添加额外的内存,因为它在我的计算机上不断崩溃。IE

"scripts":{
    "dev": "\"node --max-old-space-size=9000 yarn dev:build\""
}
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm npm-scripts yarnpkg

5
推荐指数
1
解决办法
3460
查看次数

Laravel 中的多线程

我遇到了一个问题,我的数据库调用显着减慢了页面加载速度。我正在从选举数据中填充多个图表,我的表包含大约 100 万行,我必须在方法内的每个方法中多次查询这些数据getCharts()

我正在使用它来将返回数据传递给 JavaScript。

当您单击数据点时,这些图表会重新填充。因此,如果您单击一个点 ie ('democrat),它将重新加载页面并再次调用这些方法。

我要问的是是否有可能在原生 PHP 中做这样的事情。服务器在 linode 上运行 PHP 5.2。

foreach(function in getChartsMethod){
     Start a child thread to process the function. 
}  
join the threads. 
reload the page. 


public function getCharts(){
        $this->get_cast_chart();
        $this->get_party_chart();
        $this->get_gender_chart();
        $this->get_age_chart();
        $this->get_race_chart();
        $this->get_ballot_chart();
        $this->get_county_chart();
        $this->get_precinct_chart();
        $this->get_congressional_district_chart();
        $this->get_senate_district_chart();
        $this->get_house_district_chart();
        return view('elections.index');
    }
Run Code Online (Sandbox Code Playgroud)

样品方法

public function get_party_chart(){
        $query = DB::table($this->tableName)
            ->select('party', DB::raw('count(*) as numVotes'))
            ->groupBy('party')
            ->orderBy('numVotes', 'ASC');

        if ($this->filterParameters != null){
            $query = $query->where(key($this->filterParameters), $this->operator, current($this->filterParameters));
        }
        $chartData = …
Run Code Online (Sandbox Code Playgroud)

php multithreading asynchronous laravel laravel-queue

4
推荐指数
1
解决办法
3万
查看次数

Vue,如何在渲染方法中将数据传递到组件

这是主要的vue组件。我想发出ajax请求,并使用render方法将数据传递给我的应用程序组件,该组件是另一个文件中的独立组件。如何传递这些数据以及如何在我的应用程序组件中检索它们。我正在学习Vue,我知道该怎么做,<template></template>但想知道是否可以这样做。

new Vue({
    el: '#app',
    data: {
        data: {}
    },
    mounted() {
        axios.get("http://stag.cyberserge.com:4000/autos").then(res => this.data = res.data)
    },
    render: h => h(App, this.data)
});
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2

3
推荐指数
1
解决办法
2381
查看次数

节点 Mysql 转义 - Mysql.Escape() / Mysql.EscapeId()

我正在使用 mysql-node: https: //github.com/mysqljs/mysqlMysql.Escape()但我对默认清理、 vs和vsMysql.EscapeId()的使用有点困惑。文档说????

默认清理

当您将对象传递给 .escape() 或 .query() 时,.escapeId() 用于避免对象键中的 SQL 注入。

我看到术语“对象”,那么这是否意味着我仍然应该转义这样的查询?

UPDATE table SET updated_at = userInput WHERE name = userInput

Mysql.Escape() 与 Mysql.EscapeId()
这两个函数有什么区别。文档说 mysql.escape 使用 mysql.escapeId。我知道它们都会清理输入,但是是否存在使用其中之一的情况?

?与??
文档中???可以互换使用。它们的意思是一样的吗?

node.js node-mysql mysqljs

3
推荐指数
1
解决办法
5247
查看次数