Ryan Garde
Ryan Garde

Reputation: 932

How do I view doc/txt/enc file in browser

I need to view a doc/txt/enc file from my server but whenever I enter its url in my browser it automatically downloads the file. I just want to view it using a content-type: text/plain; charset=utf-8 Like this one enter image description here

Edit: I want it to look like this: enter image description here

Upvotes: 0

Views: 458

Answers (1)

Christian Vincenzo Traina
Christian Vincenzo Traina

Reputation: 10384

Following what's said in the comments, you can change the code that serves statically your folder:

app.use('/public', express.static('public', {
  setHeaders: (res, path) => {
    if (path.endsWith('.enc')) {
      res.type('application/json');
    }
  }
}));

Upvotes: 1

Related Questions