Skip to content

Instantly share code, notes, and snippets.

@MadcapJake
Last active August 29, 2015 14:14
Show Gist options
  • Save MadcapJake/21bd83dad31ebd76f29f to your computer and use it in GitHub Desktop.
Save MadcapJake/21bd83dad31ebd76f29f to your computer and use it in GitHub Desktop.
Ceylon Express attempt
dynamic Express {}
Application requireExpressAndCallConstructor() {
dynamic { return require("express")(); }
}
dynamic Request {}
dynamic Response {
shared formal void send(String string);
}
dynamic Application {
shared formal void get(String path,
Anything(Request, Response)|Null|Anything(Request, Response)[] callbacks=null);
shared formal Server listen(Integer integer, Anything() callable);
}
dynamic Path {
}
dynamic Server {
shared formal dynamic address();
}
"Run the module `my.express`."
shared void run() {
Application app = requireExpressAndCallConstructor();
app.get("/", (Request req, Response res) {
return res.send("Hello world!");
});
Server server = app.listen(3000, () {
//dynamic host = server.address().address;
//dynamic port = server.address().port;
dynamic {
console.log(
"Example app listening..."// at http://%s:%s",
//host,
//port
);
}
return nothing;
});
}
@MadcapJake
Copy link
Author

I've updated the code per your suggestions @chochos and I am now getting a new error that I don't understand 😕

if(type.t.$$.T$name in obj.getT$all()){
                           ^
TypeError: Cannot use 'in' operator to search for 'my.express::Application' in undefined
    at is$ (C:\Users\madca_000\.eclipse\org.eclipse.platform_4.4.1_1167611518_win32_win32_x86_64\plugins\com.redhat.ceylon.dist.repo_1.1.0.v20141013-1416\repo\ceylon\language\1.1.0\ceylon.language-1.1.0.js:188:28)
    at Object.dre$$ (C:\Users\madca_000\.eclipse\org.eclipse.platform_4.4.1_1167611518_win32_win32_x86_64\plugins\com.redhat.ceylon.dist.repo_1.1.0.v20141013-1416\repo\ceylon\language\1.1.0\ceylon.language-1.1.0.js:634:5)
    at requireExpressAndCallConstructor (C:\Users\madca_000\eclipse\ceylon-express-raw\modules\my\express\1.0.0\my.express-1.0.0.js:76:17)
    at run (C:\Users\madca_000\eclipse\ceylon-express-raw\modules\my\express\1.0.0\my.express-1.0.0.js:13:13)
    at [eval]:1:292
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:536:25)
    at startup (node.js:80:7)
    at node.js:906:3

I know it has to do with calling the return of require (i.e., require("express")(); ) but that is how the JavaScript is done. Here is the example given in the Express.js docs:

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  ...
})

var server = app.listen(3000, function () {

  ...

})

And when I don't call the return (i.e., require("express"); ), I get this:

    $3i.$_get("/",m$3h.$JsCallable((function($3j,$3k){
        ^
TypeError: Object function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };

  mixin(app, proto);
  mixin(app, EventEmitter.prototype);

  app.request = { __proto__: req, app: app };
  app.response = { __proto__: res, app: app };
  app.init();
  return app;
} has no method '$_get'
    at run (C:\Users\madca_000\eclipse\ceylon-express-raw\modules\my\express\1.0.0\my.express-1.0.0.js:14:9)
    at [eval]:1:292
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:536:25)
    at startup (node.js:80:7)
    at node.js:906:3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment