Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctx.req.url打印出来的路径问题 #8

Open
wjun52 opened this issue Apr 24, 2018 · 7 comments
Open

ctx.req.url打印出来的路径问题 #8

wjun52 opened this issue Apr 24, 2018 · 7 comments

Comments

@wjun52
Copy link

wjun52 commented Apr 24, 2018

我在render方法中打印出来ctx.req.url得到的是/favicon.ico,并不是/或者/about

@yangfan0095
Copy link
Owner

我回去看一下 ,这个点还在加班😕

@yangfan0095
Copy link
Owner

yangfan0095 commented Apr 24, 2018

@guanren 应该是顺序写错了
server/app.js 入口文件

把这行代码app.use(require('koa-static')(__dirname + '../build'))app.use(index.routes(), index.allowedMethods()) 这两个中间件调用顺序改一下应该就可以了。

koa2 是洋葱模型, 中间件进入的时候会被压倒一个栈里面 ,执行compose 方法来调用中间件函数.源码如下 从右往左。

 return dispatch(0)
    function dispatch (i) {
      if (i <= index) return Promise.reject(new Error('next() called multiple times'))
      index = i
      let fn = middleware[i]
      if (i === middleware.length) fn = next
      if (!fn) return Promise.resolve()
      try {
        return Promise.resolve(fn(context, function next () {
          return dispatch(i + 1)
        }))
      } catch (err) {
        return Promise.reject(err)
      }
    }

server/app.js

app.use(json())
app.use(logger())
app.use(require('koa-static')(__dirname + '../build'))

// routes
app.use(index.routes(), index.allowedMethods())
app.use(staticCache (path.resolve(__dirname,'../build'),{
  maxAge: 365 * 24 * 60 * 60,
  gzip:true
}));

@yangfan0095
Copy link
Owner

@guanren 我已经改了 你pull 一下 看可以吗🙂

@wjun52
Copy link
Author

wjun52 commented Apr 25, 2018

listen on:3008
<-- GET /static/js/main.js.map
/static/js/main.js.map
<-- GET /main.css.map
/main.css.map
<-- GET /static/css/main.css.map
/static/css/main.css.map
--> GET /main.css.map 200 47ms 260b
--> GET /static/css/main.css.map 200 41ms 269b
<-- GET /service-worker.js
/service-worker.js
--> GET /service-worker.js 200 23ms 1.33kb

打印出来的还是文件路径,导致并没有到renderToString这一步

@nativeyou
Copy link

对的,我也是发现这个问题,导致页面源码无法渲染出对应的源码而完全走了静态资源

@zhangyanling77
Copy link

同问,并没有看到renderToString的内容

@beileixinqing
Copy link

listen on:3008
<-- GET /static/js/main.js.map
/static/js/main.js.map
<-- GET /main.css.map
/main.css.map
<-- GET /static/css/main.css.map
/static/css/main.css.map
--> GET /main.css.map 200 47ms 260b
--> GET /static/css/main.css.map 200 41ms 269b
<-- GET /service-worker.js
/service-worker.js
--> GET /service-worker.js 200 23ms 1.33kb

打印出来的还是文件路径,导致并没有到renderToString这一步

请问大家有什么解决办法吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants