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

mount koa-ejs@2 with koa-mount fails #33

Closed
pasupulaphani opened this issue Dec 20, 2016 · 3 comments
Closed

mount koa-ejs@2 with koa-mount fails #33

pasupulaphani opened this issue Dec 20, 2016 · 3 comments

Comments

@pasupulaphani
Copy link

pasupulaphani commented Dec 20, 2016

When mounting another app:

Example code:

var client1 = koa();  
render(client1, {
    root: path.join(__dirname, "view"),
    viewExt: "html",
    cache: false,
    debug: true
  });
client1.context.render = co.wrap(app.context.render);

client1.use(async (ctx, next) => {
    await ctx.render(view, locals);
});

var app = koa();  
app.use(mount("/demo", client1)

Error:

"ctx.render is not a function"
{"name":"ps-search","hostname":"Phani-Pearlshare.local","pid":67479,"level":50,"req":{"method":"GET","url":"/","headers":{"host":"localhost:8080","connection":"keep-alive","pragma":"no-cache","cache-control":"no-cache","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) A
ppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","accept-encoding":"gzip, deflate, sdch, br","accept-language":"en-GB,en-US;q=0.8,en;q=0.6","cookie":"DFTT_END_USER_AUTH_TOKEN=derhv5sa32t86pdhkgcrwyvbirss8wk36
wfegi; DFTT_REALTIME_SESSION_TOKEN=sT9byMt5s1I2bILfzjy2jzJC-1gKYmslRc1RFkAptVqwLELpPoC5xUthRbeHXWf6P96Sc49yy50wy0kNQnkKWw.8-1; DFTT_END_USER_ID=10628333; cookieconsent_dismissed=yes; _ga=GA1.1.1305685054.1470246540; driftt_aid=7dc5c5af-5b35-4874-8c16-a92041ab68a2; driftt_wmd=true; DFTT_END_USER_PREV_BOOTSTRAPPED=true
; connect.sid=s%3Ap4MlIDqncrnWj50o1SogZgp3.wSsF%2FSEbxRWp2PIeiXAUg7dsNUS55J5kNtPn47mwgmA"},"remoteAddress":"::1","remotePort":55063},"res":{},"err":{"message":"ctx.render is not a function","name":"TypeError","stack":"TypeError: ctx.render is not a function\n    at _callee$ (/Users/Phani/new_work/ps-search/clients/de
mo/index.js:21:13)\n    at tryCatch (/Users/Phani/new_work/ps-search/node_modules/regenerator-runtime/runtime.js:64:40)\n    at Generator.invoke [as _invoke] (/Users/Phani/new_work/ps-search/node_modules/regenerator-runtime/runtime.js:355:22)\n    at Generator.prototype.(anonymous function) [as next] (/Users/Phani/ne
w_work/ps-search/node_modules/regenerator-runtime/runtime.js:116:21)\n    at step (/Users/Phani/new_work/ps-search/clients/demo/index.js:29:191)\n    at /Users/Phani/new_work/ps-search/clients/demo/index.js:29:437\n    at /Users/Phani/new_work/ps-search/clients/demo/index.js:29:99\n    at /Users/Phani/new_work/ps-sea
rch/clients/demo/index.js:20:1\n    at dispatch (/Users/Phani/new_work/ps-search/node_modules/koa-compose/index.js:44:32)\n    at next (/Users/Phani/new_work/ps-search/node_modules/koa-compose/index.js:45:18)\n    at send.then.done (/Users/Phani/new_work/ps-search/node_modules/koa-static/index.js:43:20)"},"duration":
30,"msg":"  --> GET /demo 500 30ms","time":"2016-12-20T17:24:51.737Z","v":0}
@lbeeon
Copy link

lbeeon commented Jun 20, 2017

I had same problem.

@Runrioter
Copy link
Collaborator

Because app.context.render is undefined.
Just delete this line: client1.context.render = co.wrap(app.context.render);
The following statement had assigned to it:

render(client1, {
    root: path.join(__dirname, "view"),
    viewExt: "html",
    cache: false,
    debug: true
});

@tans
Copy link

tans commented Jan 5, 2023

I had the same problem.

I need to set ctx.render manual.

app.use(async (ctx, next) => {
    ctx.render = app.context.render;
    await next();
});

this work for me.

in this issue's solution like below

var client1 = koa();  
render(client1, {
  root: path.join(__dirname, "view"),
  viewExt: "html",
  cache: false,
  debug: true
}); 



client1.use(async (ctx, next) => {
    ctx.render = client1.context.render;
    await next();
});

client1.use(async (ctx, next) => {
    await ctx.render(view, locals);
});
 
app.use(mount("/demo", client1)

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

4 participants