koajs / kick-off-koa Goto Github PK
View Code? Open in Web Editor NEW[MAINTAINERS WANTED] An intro to koa via a set of self-guided workshops
License: MIT License
[MAINTAINERS WANTED] An intro to koa via a set of self-guided workshops
License: MIT License
By introducing ctx with no explanation, the developer is required to go out and read the koa documentation. This wouldn't be an issue, but the expressjs/cookies page linked in the exercise doesn't have any documentation on how to use cookies with koa, only express, and the link off of the koa documentation page is different (but ends up in the same place). Initially I was under the false impression that I needed to require() it in. Perhaps linking in the koa cookie docs under the hint would help clarify.
Test 3 fails, I've tried copy/paste your solution and the same result is returned: -
Your submission results compared to the expected:
────────────────────────────────────────────────────────────────────────────────
Tobi is a 3 year old ferret.
"Tobi is a 3 year old ferret.
"────────────────────────────────────────────────────────────────────────────────
✗ Submission results match expected
Your solution to TEMPLATING didn't pass. Try again!
Hello,
Im trying to solve this problem and solved it.
Then I looked at the official answer and I think there is something not right.
The problem stated : If it's application/json, return {message: 'hi!'} with appropriate content headers
And in the official answer I do not see the content headers set.
Roelof
when I run into Exercise 4 of 11
I get the result:
1. ACTUAL: "`/json` respond body: {\"foo\":\"bar\"}"
1. EXPECTED: "`/json` respond body: {\"foo\":\"bar\"}"
2. ACTUAL: "`/json` respond content-type: application/json; charset=utf-8"
2. EXPECTED: "`/json` respond content-type: application/json; charset=utf-8"
3. ACTUAL: "`/stream` respond body: {\"foo\":\"bar\"}"
3. EXPECTED: "`/stream` respond body: Setting a stream as a body."
4. ACTUAL: "`/stream` respond content-type: application/json; charset=utf-8"
4. EXPECTED: "`/stream` respond content-type: application/octet-stream"
5. ACTUAL: "`/stream` respond transfer-encoding: undefined"
5. EXPECTED: "`/stream` respond transfer-encoding: chunked"
6. ACTUAL: ""
6. EXPECTED: ""
my source code was:
app.use(function*(next) {
if (this.path !== '/stream') {
yield next;
};
this.body = fs.createReadStream(process.argv[3]);
})
I had been read the solution, it seem that my code was correct
so is it the environment problem?
cpu:hello r$ node -v
v5.0.0
cpu:hello r$ npm -v
3.3.6
when i execute the program:
$ kick-off-koa run program.js
it runs the server, outputs the body and stops the server
The submission server will listen at port 4502
hello
how can i verify this?
the output I get is
The solution server will listen at port 4502
✗ Error connecting to solution server(http://localhost:4502/hello), options: {"timeout":5000,"maxRedirects":10}. Error: connect ECONNREFUSED
at exports._errnoException (util.js:742:11)
at Object.afterConnect [as oncomplete] (net.js:989:19)
I have included the src for reference:
var koa = require('koa');
var app = koa();
app.use(function *blah() {
// you can set the response body in handler like this
this.body = 'hello';
});
app.listen(process.argv[2]);
For example, Exercise 1 still tells you to use app = koa()
instead of the class-based notation (app = new Koa()
).
And once you change this, koa tells you that generators are now deprecated and will be removed:
PS D:\koa-test1> node server
koa deprecated Support for generators will be removed in v3. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/blob/mas
ter/docs/migration.md server.js:6:5
I don't know when v3 comes out, but it seems this repo is already out of date for the current version, so it makes sense to go straight to v3.
After copying and pasting the solution, I still get the following error:
Server listening at port 63797
✗ Error connecting to submission server (http://localhost:63797/), options: {"requestUrls":["http://localhost:63797/"],"timeout":[5000,5000],"maxRedirects":10}. ConnectionTimeoutError: Connect timeout for 5000ms, GET http://localhost:63797/ -2 (connected: false, keepalive socket: false)
headers: {}
at Timeout._onTimeout (/usr/local/lib/node_modules/kick-off-koa/node_modules/urllib/lib/urllib.js:701:15)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
Code:
var koa = require('koa');
var app = koa();
app.use(function* (next) {
if (this.path !== '/') {
return yield next;
}
this.body = 'hello koa';
});
app.use(function* (next) {
if (this.path !== '/404') {
return yield next;
}
this.body = 'page not found';
});
app.use(function* (next) {
if (this.path !== '/500') {
return yield next;
}
this.body = 'internal server error';
});
var port = process.argv[2];
app.listen(port, function () {
console.log('Server listening at port ' + port);
});
Node Version:
7.1.0
OS:
10.12.1
Kick off koa:
[email protected]
This solution works as expected if visiting from the browser.
I've been giving the workshop today, and I've found some of the concepts can be pretty confusing to grasp. Maybe we should think about ways to make these concepts more clearer. The concepts that were hard to grok are:
What do you think? How can we make this better? :D
Hi when i verify my answer for routing exercice i have this error:
/home/mnk/Documents/dev/nodeDev/koa/node_modules/koa/node_modules/co/index.js:88
if (ret.done) return Promise.resolve(ret.value);
^
ReferenceError: Promise is not defined
at next (/home/mnk/Documents/dev/nodeDev/koa/node_modules/koa/node_modules/co/index.js:88:26)
at onFulfilled (/home/mnk/Documents/dev/nodeDev/koa/node_modules/koa/node_modules/co/index.js:59:12)
at Object.co (/home/mnk/Documents/dev/nodeDev/koa/node_modules/koa/node_modules/co/index.js:44:10)
at Object. (/home/mnk/Documents/dev/nodeDev/koa/node_modules/koa/node_modules/co/index.js:28:15)
at Server. (/home/mnk/Documents/dev/nodeDev/koa/node_modules/koa/lib/application.js:123:8)
at Server.EventEmitter.emit (events.js:107:17)
at HTTPParser.parserOnIncoming as onIncoming
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
at Socket.socketOnData (_http_server.js:357:22)
at Socket.EventEmitter.emit (events.js:104:17)
✗ Error connecting to submission server(http://localhost:45317/404), options: {"timeout":5000,"maxRedirects":10}. Error: connect ECONNREFUSED
at exports._errnoException (util.js:745:11)
at Object.afterConnect as oncomplete
I am getting this particular error. However, node --harmony server.js
is working fine. I am on exercise#2 Routing
. I get the same error on kick-off-koa verify server.js
. Node
version is v0.11.14
, koa
is v0.12.2
and kick-off-koa
is v1.1.1
~/P/n/koa ∴ cat server.js
var koa = require('koa')
var app = koa();
app.use(function *(next) {
// skip the rest of the code if the route does not match
if (this.path !== '/') return yield next;
this.body = 'we are at home!';
});
app.listen(3000);
~/P/n/koa ∴ kick-off-koa run server.js
✗ Error connecting to submission server(http://localhost:64534/), options: {"timeout":5000,"maxRedirects":10}. Error: connect ECONNREFUSED
at exports._errnoException (util.js:742:11)
at Object.afterConnect [as oncomplete] (net.js:982:19)
^C
Navigating to Choose Language
and either choosing a language or Cancel
, then at the main menu choosing an exercise, results in the following error:
events.js:72
listeners[i].call(self);
^
TypeError: Cannot read property 'call' of undefined
at emitNone (events.js:72:19)
at Stream.emit (events.js:166:7)
at Stream.Charm.end (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/workshopper/node_modules/terminal-menu/node_modules/charm/index.js:107:10)
at Menu.close (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/workshopper/node_modules/terminal-menu/index.js:126:16)
at Menu.<anonymous> (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/workshopper/menu.js:75:10)
at emitTwo (events.js:92:20)
at Menu.emit (events.js:172:7)
at Menu.ondata [as _ondata] (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/workshopper/node_modules/terminal-menu/index.js:215:18)
at DestroyableTransform._transform (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/workshopper/node_modules/terminal-menu/index.js:50:18)
at DestroyableTransform.Transform._read (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (~/Documents/npm-global/lib/node_modules/kick-off-koa/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
In the task of error handler, the response cannot be set with ctx.body = 'internal server error'
. Here is my error handler :
function errorHandler(ctx, next) {
try {
return next();
}
catch(err) {
ctx.status = err.status || 500;
ctx.body = 'internal server error';
// emit can't help
// ctx.app.emit('error', err, ctx);
}
}
When I verify my codes, the third test always fails :
3. ACTUAL: "responds "Internal Server Error" when requesting /error
"
3. EXPECTED: "responds "internal server error" when requesting /error
"
Hello,
Why is for example koa-router not used for this exercise.
It makes much more sense then working with path and a lot of if 's
Roelof
i mean this one
Meanwhile we are migrating to kao 2 and
Why i passed test?
var koa = require('koa'),
parse = require('co-body'),
app = koa();
app.use(function* (next) {
if(this.path !== '/' && this.method !== 'GET') {
return yield next;
}
var body = yield parse(this);
try {
this.body = body.name.toUpperCase();
} catch(err) {
this.body = null;
}
});
app.listen(process.argv[2]);
I feel a bit weird about npm -g installing Koa as I don't like making things globally available as coding packages when they are more coding tutorial programs...
Do you want us to make you a Windows installer for this, or better yet a shiny looking webpage?
I'm sure our other Junior Dev could do that, in between writing silly blog posts (@Clown-Fox !!)
var n = ~~this.cookies.get('view', { signed: true }) + 1;
what does ~~ mean ? thanks
I find it reports error when selecting CHOOSE LANGUAGE
again.
$> kick-off-koa
CHOOSE LANGUAGE
then select French
(or English
)CHOOSE LANGUAGE
events.js:72
listeners[i].call(self);
^
TypeError: Cannot read property 'call' of undefined
at emitNone (events.js:72:19)
at Stream.emit (events.js:166:7)
at Stream.Charm.end (/usr/local/lib/node_modules/kick-off-koa/node_modules/charm/index.js:107:10)
at Menu.close (/usr/local/lib/node_modules/kick-off-koa/node_modules/terminal-menu/index.js:126:16)
at Menu.<anonymous> (/usr/local/lib/node_modules/kick-off-koa/node_modules/workshopper/menu.js:75:10)
at emitTwo (events.js:92:20)
at Menu.emit (events.js:172:7)
at Menu.ondata [as _ondata] (/usr/local/lib/node_modules/kick-off-koa/node_modules/terminal-menu/index.js:215:18)
at DestroyableTransform._transform (/usr/local/lib/node_modules/kick-off-koa/node_modules/terminal-menu/index.js:50:18)
at DestroyableTransform.Transform._read (/usr/local/lib/node_modules/kick-off-koa/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/usr/local/lib/node_modules/kick-off-koa/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/usr/local/lib/node_modules/kick-off-koa/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/usr/local/lib/node_modules/kick-off-koa/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (/usr/local/lib/node_modules/kick-off-koa/node_modules/readable-stream/lib/_stream_writable.js:194:11)
node
version is v5.3.0
I can't verify first exercise, even if I copy it's source from this repository.
After I try "kick-off-koa verify ex1.js" I get following error:
/Users/nikolaykletskin/projects/nodeschool/koa/node_modules/koa/node_modules/composition/node_modules/any-promise/register.js:61
throw new Error('Cannot find any-promise implementation nor'+
^
Error: Cannot find any-promise implementation nor global.Promise. You must install polyfill or call require("any-promise/register") with your preferred implementation, e.g. require("any-promise/register")("bluebird") on application load prior to any require("any-promise").
at register (/Users/nikolaykletskin/projects/nodeschool/koa/node_modules/koa/node_modules/composition/node_modules/any-promise/register.js:61:11)
at Object. (/Users/nikolaykletskin/projects/nodeschool/koa/node_modules/koa/node_modules/composition/node_modules/any-promise/index.js:1:101)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object. (/Users/nikolaykletskin/projects/nodeschool/koa/node_modules/koa/node_modules/composition/index.js:2:15)
at Module._compile (module.js:449:26)
✗ Error connecting to submission server (http://localhost:51186/hello), options: {"timeout":5000,"maxRedirects":10}. Error: connect ECONNREFUSED
at exports._errnoException (util.js:742:11)
at Object.afterConnect as oncomplete
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.