polyccon / Crumbs

A library for all your favourite biscuits!
http://crumbs-fac.herokuapp.com/
0 stars 0 forks source link

Easier way to find ext for your endpoints. #43

Open sohilpandya opened 7 years ago

sohilpandya commented 7 years ago

In this file https://github.com/polyccon/Crumbs/blob/master/src/handler.js#L9-L16

You are defining the extensions, but what happens if you add png files, then add svg files to serve. You will constantly be adding to this list.

Have you thought about an alternative?

You could just split the url to get the ext.

var ext = url.split('.')[1];
// this will give you the extension as long as you have the url. which you can get from the request. 
dangerdak commented 7 years ago

@sohilpandya thanks. We use that object to get the content-types based on the extension - is there a better way to do this?

sohilpandya commented 7 years ago

What you are doing is good, in the future you'll probably be better off using a module which makes this easier for you. hint -> serve-static

😉