iosgcdwebserver

How to get local html file through gcdwebserver


I am running local GCDWebServer in iphone simulator,I stored some html files inside document directory,right now i want to access that html file through gcdwebserver,i am trying but not getting response,please help me

code:

[self addGETHandlerForBasePath:@"/" directoryPath:folderpath indexFilename:nil cacheAge:3600 allowRangeRequests:YES];

[self addHandlerForMethod:@"GET"
                pathRegex:@"/.*\.html"
             requestClass:[GCDWebServerRequest class]
             processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

    NSDictionary* variables = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"variable", nil];
    return [GCDWebServerDataResponse responseWithHTMLTemplate:[websitePath stringByAppendingPathComponent:request.path]
                                                    variables:variables];

}];


[self addHandlerForMethod:@"GET"
                     path:@"/"
             requestClass:[GCDWebServerRequest class]
             processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

    return [GCDWebServerResponse responseWithRedirect:[NSURL URLWithString:@"index.html" relativeToURL:request.URL]
                                            permanent:NO];

];

Solution

  • You probably don't have websitePath set correctly, try:

    websitePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];