Admin UI not worked after setting header in static directory 'Public'

20 views
Skip to first unread message

Arul

unread,
Jul 16, 2019, 5:20:34 AM7/16/19
to Keystone JS

I tried to add the header for the static files in public when I try this below code The Admin CMS not worked, how to set static files header.

var keystone = require('keystone');
var path = require('path');
var fs = require('fs');
var morgan = require('morgan');
var serveStatic = require('serve-static');
var express = require('express');
var app = express();

keystone.init({
  'name': 'TestDemo',
  'session': true,
  'static': 'public',
  'user model': 'admin',
  'auto update': true,
  'auth': true,
  'views': 'templates/views',
  'view engine': 'pug',
  'file limit': '2MB',
});
keystone.import('./app/models');
keystone.set('routes', require('./app/routes/routes'));

const setCustomCacheControl = function (res) {
  res.header('X-Frame-Options', 'DENY');
  res.header('x-xss-protection', '1');
  res.header('X-Content-Type-Options', 'nosniff');
  res.header('Referrer-Policy', 'no-referrer');
  res.header('X-Permitted-Cross-Domain-Policies', 'none');
  res.header('Strict-Transport-Security', ' max-age=31536000');
  res.header('X-Download-Options', 'noopen');
  res.header('X-Robots-Tag', 'none');
  res.header('Cache-Control', 'no-cache, no-store, must-revalidate');
  res.removeHeader('x-powered-by');
  res.removeHeader('server');
};

app.use(serveStatic('public', {
  setHeaders: setCustomCacheControl
}));

keystone.app = app;
keystone.start();

Reply all
Reply to author
Forward
0 new messages