Support #1992
closedAdd static resource to main application path
0%
Description
Hello! I wan't to know is it possible (and is it make sense) to add static resource with WServer::addResource to main application path.
I tried server->addResource(new MyResource, "/") but virtual method handleRequest is not calling when i send http requests to: localhost:port or ocalhost:port/
I think that this path is allready used by application so I can't add to it my resource. Is it true?
Updated by Vitaly Volochay almost 11 years ago
And the other question is: what is a best way to pass data from static resource to WApplication.
I thought about 2 ways:
1) Emit signal from WResource::handleRequest() and somehow connect it with WApplication;
2) Use WServer::post from WResource::handleRequest() for post data to same session.
Updated by Koen Deforche almost 11 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
Hey,
By default, the application is deployed at '/' but you can change that using the ---deploy-path parameter, or by deploying the application on a different path using WServer API.
As to your second question, definitely the second method (2) is what you should do.
Regards,
koen
Updated by Vitaly Volochay almost 11 years ago
Trying to process http requests like this:
Wt::WServer server(argv[0]);
WebAppResource resource;
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
server.addEntryPoint(Wt::Application, createApplication);
server.addResource(&resource, "/service");
server.start()
and:
void WebAppResource::handleRequest(const Request& request, Response& response)
{
MyWebApplication* app = dynamic_cast<MyWebApplication*>(WApplication::instance());
WServer* server = WServer::instance();
if (app && server)
{
server~~post(app~~>sessionId(), boost::bind(&MyWebApplication::processHttp, app,
WString(request.queryString())));
}
}
but when 'handleRequest' is called WApplication::instance() always returns null-pointer although it allready created, so I can't post event. What should i do?
Updated by Koen Deforche almost 11 years ago
Hey,
a static resource is not linked to a WApplication, and thus WApplication::instance() is null by definition. Also, handleRequest() expects a response so you need to provide one by the time the function exits (or create a continuation otherwise).
What do you really want to do? Perhaps you want to set a cookie from the WApplication which you then check in the resource request which identifies the application context in which the request is to be handled?
What's the use-case? Why not use a normal dynamic WResource() within the application context?
Regards,
koen
Updated by Vitaly Volochay over 10 years ago
Thanks for your answer I find another way to solve my problem.
Updated by Koen Deforche over 10 years ago
- Status changed from Feedback to Closed
- Target version deleted (
3.3.0)