Skip to content

Commit

Permalink
Add favicons
Browse files Browse the repository at this point in the history
  • Loading branch information
thesephist committed Apr 1, 2019
1 parent 8fb4110 commit 8de4afd
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
PORT: 4556,
PORT: process.env.PORT || 4556,
DATABASE: 'db',
}
24 changes: 18 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,34 @@ app.use(bodyParser.text({

const api = require('./api.js');

const CONTENT_TYPES = {
'.js': 'text/javascript',
'.html': 'text/html',
'.ico': 'image/x-icon',
}

// STATIC ASSETS
const STATIC_PATHS = {
'/': 'index.html',
'/new': 'editor.html',
'/favicon.ico': 'assets/favicon.ico',
'/h/:htmlFrameHash/j/:jsFrameHash/edit': 'editor.html',
}
const respondWith = (res, static_path) => {
fs.readFile(`static/${static_path}`, 'utf8', (err, data) => {
fs.readFile(`static/${static_path}`, (err, data) => {
if (err) {
throw err;
}

res.set('Content-Type', 'text/html');
let contentType = 'text/html';
for (const [ending, type] of Object.entries(CONTENT_TYPES)) {
if (static_path.endsWith(ending)) {
contentType = type;
break;
}
}

res.set('Content-Type', contentType);
res.set('X-Frame-Options', 'SAMEORIGIN');
res.send(data);
});
Expand All @@ -48,10 +63,6 @@ app.get('/f/:htmlFrameHash/:jsFrameHash.html/edit', (req, res) => {
});

// API
const CONTENT_TYPES = {
'.js': 'text/javascript',
'.html': 'text/html',
}
const API_PATHS = {
'GET /api/frame/:frameHash': api.frame.get,
'POST /api/frame/': api.frame.post,
Expand All @@ -72,6 +83,7 @@ for (const [spec, handler] of Object.entries(API_PATHS)) {
for (const [ending, type] of Object.entries(CONTENT_TYPES)) {
if (route.endsWith(ending)) {
contentType = type;
break;
}
}

Expand Down
Binary file added static/assets/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/assets/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/assets/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions static/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Codeframe Editor</title>
<link rel="stylesheet" href="/static/css/main.css">
<link rel="icon" type="image/png" href="/static/assets/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/static/assets/favicon-16x16.png" sizes="16x16" />
</head>

<body>
Expand Down
4 changes: 3 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<title>Codeframe | A Playground for the Web</title>
<link rel="stylesheet" href="/static/css/main.css">
<link rel="stylesheet" href="/static/css/index.css">
</head>
<link rel="icon" type="image/png" href="/static/assets/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/static/assets/favicon-16x16.png" sizes="16x16" />
</head>

<body>
<header>
Expand Down

0 comments on commit 8de4afd

Please sign in to comment.