Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
Add favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
k4m4 committed Dec 18, 2019
1 parent bed7924 commit c93ca7b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
Binary file added favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions index.ts
Expand Up @@ -9,6 +9,8 @@ import serveMarked from 'serve-marked'
const jm = jaymock()
jm.extend('chance', new chance())

const readFile = (name: string): Buffer => readFileSync(join(__dirname, name))

const serveReadme = serveMarked(readFileSync(join(__dirname, 'readme.md')).toString('utf8'), {
title: 'jaymock',
inlineCSS: `
Expand All @@ -19,7 +21,9 @@ const serveReadme = serveMarked(readFileSync(join(__dirname, 'readme.md')).toStr
height: 20px;
}
`,
beforeHeadEnd: '<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/github-gist.min.css" rel="stylesheet" />',
beforeHeadEnd:
'<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/github-gist.min.css" rel="stylesheet" />' +
'<link rel="icon" href="/favicon.png" sizes="32x32" />',
beforeBodyEnd:
'<script charset="UTF-8" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"></script>' +
'<script>hljs.initHighlightingOnLoad();</script>'
Expand All @@ -31,9 +35,9 @@ export default async (req: IncomingMessage, res: ServerResponse): Promise<any> =
case '/':
return serveReadme(req, res)
case '/demo.gif':
return readFileSync(join(__dirname, 'demo.gif'))
case '/favicon.ico':
return ''
return readFile('demo.gif')
case '/favicon.png':
return readFile('favicon.png')
default:
return 'Use POST request.'
}
Expand Down
4 changes: 4 additions & 0 deletions now.json
Expand Up @@ -6,6 +6,10 @@
"src": "*.gif",
"use": "@now/static"
},
{
"src": "*.png",
"use": "@now/static"
},
{
"src": "index.ts",
"use": "@now/node@canary"
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -74,6 +74,7 @@
"file-type": "^12.4.0",
"freddo": "^1.1.3",
"got": "^10.0.2",
"is-png": "^2.0.0",
"micro-dev": "^3.0.0",
"nyc": "^15.0.0-beta.2",
"test-listen": "^1.1.0",
Expand Down
6 changes: 3 additions & 3 deletions test.ts
Expand Up @@ -4,6 +4,7 @@ import got from 'got'
import micro from 'micro'
import testListen from 'test-listen'
import fileType from 'file-type'
import isPNG from 'is-png'
import m from '.'

const template = {
Expand Down Expand Up @@ -80,10 +81,9 @@ test('valid GET request', async t => {
.body((body: string) => isGIF(Buffer.from(body, 'utf8')))
.ensure()

await freddo(`${url}/favicon.ico`)
await freddo(`${url}/favicon.png`, {encoding: null})
.status(200)
.header('content-length', 0)
.body('')
.body((body: string) => isPNG(Buffer.from(body)))
.ensure()

await freddo(`${url}/xyz`)
Expand Down

0 comments on commit c93ca7b

Please sign in to comment.