Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 479516

Summary: Migrating the Node server from Connect to Express
Product: [ECD] Orion Reporter: Chen-Yu Kevin Leong <c2leong>
Component: NodeAssignee: Mark Macdonald <mamacdon>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: maciej.bendkowski, mamacdon, pwebster
Version: 10.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows NT   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=488342
Whiteboard:

Description Chen-Yu Kevin Leong CLA 2015-10-11 12:22:29 EDT
Goal: Use Express to reduce boiler plate code on Node.
Comment 1 Chen-Yu Kevin Leong CLA 2015-10-11 13:15:41 EDT
Hi Mark,
I am working on migrating node-orion from Connect to Express. I found many documentations and tutorials on Express, but was unable to find many documentations or tutorials on Connect. So I was hoping you could provide me with some hints as to what Express does that Connect doesn't and why we are trying to perform the migration.
Thanks,
Kevin
Comment 2 Maciej Bendkowski CLA 2015-10-11 14:05:55 EDT
(In reply to Chen-Yu Kevin Leong from comment #1)
> I found many
> documentations and tutorials on Express, but was unable to find many
> documentations or tutorials on Connect.

Have you visited their official github page [1]? You could also take a look at [2] - a short introduction guide to connect.

[1] https://github.com/senchalabs/connect
[2] http://stephensugden.com/middleware_guide/
Comment 3 Chen-Yu Kevin Leong CLA 2015-10-11 14:30:50 EDT
(In reply to Maciej Bendkowski from comment #2)
> (In reply to Chen-Yu Kevin Leong from comment #1)
> > I found many
> > documentations and tutorials on Express, but was unable to find many
> > documentations or tutorials on Connect.
> 
> Have you visited their official github page [1]? You could also take a look
> at [2] - a short introduction guide to connect.
> 
> [1] https://github.com/senchalabs/connect
> [2] http://stephensugden.com/middleware_guide/

I had not read [2]. I shall read it now. Thanks for the links.
Comment 4 Chen-Yu Kevin Leong CLA 2015-12-05 19:07:46 EST
Files I made edits to:
index.js
server.js
  - wrote code for basic-auth
  - wrote code for express
  - created an express app
  - created a http server
file.js
  - wrote code for express
  - wrote code for express-json
git.js
  - wrote code for express
  - wrote code for express-json
orion_static.js
  - wrote code for mime
  - wrote code for express
  - wrote code for express.static
orionnode_static.js
  - wrote code for express
  - wrote code for express.static
search.js
  - wrote code for express
  - wrote code for express-json
workspace.js
  - wrote code for express
  - wrote code for express-json
test_data.js
  - wrote code for express

package.json
  - added modules to install
    - express-json
    - mime
    - express
    - basic-auth
    - compression

Things I learned from this project:
- Takes a lot of time to understand this much code. It takes a lot of understanding and debugging to locate the source of problems, even for simple fixes. 
- Learned how to use the Chrome Developer tool to debug.
- The importance of communication. There were many cases where I thought my code was working, but it actually wasn't. 
- Much stronger understanding of Java Script, Node.js, Express.js.
Comment 5 Paul Webster CLA 2015-12-08 12:21:30 EST
I get a strange error after I
1) do node install
2) fire up node server.js -c /path/express.conf
3) go to http://localhost:8081/

Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
    at expressInit (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/middleware/init.js:23:42)
    at Layer.handle [as handle_request] (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/index.js:312:13)
    at /opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/index.js:330:12)
    at next (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/index.js:271:10)
    at query (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/middleware/query.js:49:5)
    at Layer.handle [as handle_request] (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/opt/pwebster/openacademy/express.orion.client/modules/orionode/node_modules/express/lib/router/index.js:312:13)


I'm going to try and push your code in a branch up to the main repo.

PW
Comment 6 Paul Webster CLA 2015-12-08 12:52:00 EST
I've pushed it up to pwebster/bug479516
https://git.eclipse.org/c/orion/org.eclipse.orion.client.git/log/?h=pwebster/bug479516

PW
Comment 7 Mark Macdonald CLA 2016-02-23 19:56:14 EST
Starting from the branch in comment 6, I did some additional work to fix a few bugs and test failures that I found. 

All unit tests are passing (or in the case of nodegit, failing no worse than they failed before).

This has been merged into master.

Thanks Kevin!
Comment 8 Mark Macdonald CLA 2016-02-23 20:07:31 EST
Now that Express is in place, see bug 488342 for additional cleanup work
Comment 9 Mark Macdonald CLA 2016-02-24 09:07:53 EST
Commits released for this bug

> * af7c0b8 2016-02-23 | Allow tests to run without nodegit
> * 51fa1c7 2016-02-22 | Bug 479516: Fix tests under Express
> * fb795a2 2016-02-23 | Bug 479516: fix maxAge, dotfiles in `orion_static`
> * ab4a5ac 2016-02-23 | Bug 479516: fix JSON and redirect middleware under Express
> * 1243418 2016-02-22 | Bug 479516: Move auth to its own file, catch startup errors
> * 6e19985 2015-11-03 | Bug 479516 - Migrating the Node server from Connect to Express