Giter VIP home page Giter VIP logo

kick-off-koa's Introduction

kick-off-koa

NPM version build status Gittip

An intro to koa via a set of self-guided workshops.

kick-off-koa

Install

npm install -g kick-off-koa

Getting Started

After npm install -g kick-off-koa, Run kick-off-koa command.

To use kick-off-koa, you should be running node 7.6 or higher for async/await support. If you should use versions of node < 7.6, it's recommend using babel's require hook. You can check nvm or n to install node 7.6+.

If you want to play offline, install all these dependencies first:

npm install koa koa-session co-body co-views ejs

Now only english version was migrated to koa 2 but another is not. Meanwhile we are migrating to koa 2 and you can also take part in it.

Learn More

  • workshop - A workshop to learn the basics of koa, Express' spiritual successor.

License

MIT

kick-off-koa's People

Contributors

aessi avatar bananaappletw avatar bobbykostadinov avatar booxood avatar dead-horse avatar fengmk2 avatar foxandxss avatar greenkeeperio-bot avatar hemanth avatar hyeoksuhan avatar iancrowther avatar joachimboggild avatar judikdavid avatar rosspatton avatar russmatney avatar satanas avatar shiawuen avatar skovsgaard avatar tdd avatar twistedstream avatar xie-qianyue avatar yoshuawuyts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kick-off-koa's Issues

Error: connect ECONNREFUSED

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

Error connecting to submission server, lesson 2 routing.

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.

Exercise 10 fails

Test 3 fails, I've tried copy/paste your solution and the same result is returned: -

Your submission results compared to the expected:

────────────────────────────────────────────────────────────────────────────────

  1. ACTUAL: "

    Tobi is a 3 year old ferret.

    "
  2. EXPECTED: "

    Tobi is a 3 year old ferret.

    "
  3. ACTUAL: ""
  4. EXPECTED: ""
  5. ACTUAL: ""
  6. EXPECTED:

────────────────────────────────────────────────────────────────────────────────

✗ Submission results match expected

FAIL

Your solution to TEMPLATING didn't pass. Try again!

Whtat's the problem with my environment?

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

Navigating to `Choose Language` and then choosing an exercise crashes

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)

Update to support Koa 3 version

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.

routing exercise question

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

not correct verify

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]);

Feature request: Windows installer for kick-off-koa

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 !!)

readme typo

i mean this one

Meanwhile we are migrating to kao 2 and

Can't verify first exercise

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

cookies exercise hint/apis list improvements

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.

error occurs when selecting `CHOOSE LANGUAGE` again.

I find it reports error when selecting CHOOSE LANGUAGE again.

steps

  1. $> kick-off-koa
  2. select CHOOSE LANGUAGE then select French (or English)
  3. select CHOOSE LANGUAGE

error notes

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

Task of error handler with Koa 2 cannot pass

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"

discussion: background information

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:

  • generators: using them needs quite some explanation. Maybe we should create a short workshopper for these?
  • error handling: seeing unknown syntax in examples can be daunting. Error handling is pretty far down the line in the workshop, and getting exposed to it beforehand was overwhelming for some students.

What do you think? How can we make this better? :D

error message about promise && connection

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

background isn't cleared?

I'm not sure if this is a bug on my end or something, but the background isn't being cleared, and when it prints out instructions they're usually garbled with the leftover stuff from the last "scene" or "window" or whatever.
capture
capture

no sure how to verify

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]);

content headers remark

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.