Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const MIME_TYPES = {
svg: 'image/svg+xml',
};

const HEADERS = {
'X-XSS-Protection': '1; mode=block',
'X-Content-Type-Options': 'nosniff',
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload',
'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': [
'default-src \'self\'',
'style-src \'self\' https://fonts.googleapis.com',
'font-src \'self\' https://fonts.gstatic.com',
].join('; '),
};

class Client {
constructor(req, res, application, connection) {
this.req = req;
Expand All @@ -25,7 +37,7 @@ class Client {
const filePath = url === '/' ? '/index.html' : url;
const fileExt = path.extname(filePath).substring(1);
const mimeType = MIME_TYPES[fileExt] || MIME_TYPES.html;
res.writeHead(200, { 'Content-Type': mimeType });
res.writeHead(200, { ...HEADERS, 'Content-Type': mimeType });
const data = application.static.get(filePath);
if (data) res.end(data);
else this.error(404);
Expand Down
2 changes: 1 addition & 1 deletion static/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// API Builder

const socket = new WebSocket('ws://127.0.0.1:8000/');
const socket = new WebSocket('wss://' + location.host);

const buildAPI = (methods, socket = null) => {
const api = {};
Expand Down