Hey,
the method to retrieve the session id in the rest interface does not appear to work as described here.
Is there any way I can troubleshoot this case and find out what's going wrong?
app.d:
import vibe.d;
interface IMyAPI
{
string test(Session session);
}
class API : IMyAPI
{
@before!getSession("session")
string test(Session session) { return "test complete"~session.id;}
}
Session getSession(HTTPServerRequest req, HTTPServerResponse res)
{
return req.session ? req.session : res.startSession();
}
shared static this()
{
auto router = new URLRouter;
router.get("/", &index);
auto restSettings = new RestInterfaceSettings;
restSettings.baseURL = URL("http://127.0.0.1:8080/api");
router.registerRestInterface(new API(), restSettings);
router.get("/test.js", serveRestJSClient!IMyAPI(restSettings));
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.sessionStore = new MemorySessionStore;
listenHTTP(settings, router);
}
void index(HTTPServerRequest req, HTTPServerResponse res)
{
res.render!("index.dt", req);
}
index.dt:
p hello
script(src="test.js")
:javascript
console.log("test script");
IMyAPI.test({}, function(r) { console.log(r);});
Browser console result:
test script
test complete