justinfagnani / route

A client + server routing library for Dart
BSD 3-Clause "New" or "Revised" License
114 stars 40 forks source link

Example files.dart ContentTypes forFile returns null ContentType #81

Open mkhan-akhan opened 10 years ago

mkhan-akhan commented 10 years ago

In the Example in files.dart, ContentTypes.forFile returns null because _extensions map is missing a dot in the keys. path.extension(file.path) returns the extensions with a dot prefixed. Hence 'css' : CSS should be '.css' : CSS.

mkhan-akhan commented 10 years ago

It was causing my style.css to be loaded as 'text/plain' which resulted in none of the styles being applied.

akserg commented 10 years ago

I have the same problem because Path.extension function

Gets the file extension of path: the portion of basename from the last . to the end (including the . itself).

Opposite of mkhan-akhan solution I offer left extension names "as is" but make changes in forFile method like that:

static ContentType forFile(File file) {
  String ext = path.extension(file.path);
  return _extensions[ext.length > 0 ? ext.substring(1) : ext];
}