Skip to content

Commit cb2a1a4

Browse files
committed
feat: support inline resources
Add { inline: true } options to inline stylesheets and scripts. Fixes #25.
1 parent 2dce964 commit cb2a1a4

13 files changed

+359
-29
lines changed

.eslintrc.yml .eslintrc.yaml

File renamed without changes.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.*
22
node_modules
3+
dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const Koa = require('koa')
2+
const restc = require('../..')
3+
const app = new Koa()
4+
5+
app.use(restc.koa2({
6+
includes: ['/api', /^\/foo/],
7+
excludes: '/foobar'
8+
}))
9+
10+
app.listen(3000)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Koa = require('koa')
2+
const restc = require('../..')
3+
const app = new Koa()
4+
5+
app.use(restc.koa2({ inline: true }))
6+
7+
app.use((ctx, next) => {
8+
ctx.body = { message: 'Hello world!' }
9+
return next()
10+
})
11+
12+
app.listen(3000)

examples/restc-example-koa2-inline/package-lock.json

+287
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "restc-example-koa2",
3+
"version": "1.0.0",
4+
"description": "An example to demostrate how to use restc in koa 2.x.",
5+
"private": true,
6+
"main": "index.js",
7+
"author": "lujjjh <[email protected]>",
8+
"license": "MIT",
9+
"dependencies": {
10+
"koa": "^2.0.0"
11+
}
12+
}

faas/install_production.sh

-6
This file was deleted.

lib/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ const fs = require('fs')
44
const path = require('path')
55
const Gateway = require('./utils/gateway.js')
66

7-
const content = fs.readFileSync(
8-
path.join(__dirname, '../faas/index.html'),
9-
'utf-8'
10-
)
11-
127
const cache = new WeakMap()
138

149
module.exports = function (options = {}) {
1510
if (cache.has(options)) {
1611
return cache.get(options)
1712
}
1813

19-
const { includes, excludes, shouldHandle } = options
14+
const { inline, includes, excludes, shouldHandle } = options
15+
16+
const content = fs.readFileSync(
17+
path.join(__dirname, '..', 'dist', inline ? 'index.inline.html' : 'index.html'),
18+
'utf-8'
19+
)
20+
2021
const gateway = new Gateway({ includes, excludes, shouldHandle })
2122
const handler = function (req, res) {
2223
// set vary header for every response

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-12
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@
88
"typings": "index.d.ts",
99
"files": [
1010
"lib",
11-
"faas",
11+
"dist",
1212
"index.js",
1313
"index.d.ts"
1414
],
1515
"scripts": {
16+
"build": "mkdir -p dist && cp src/index.html dist/ && ./scripts/inline.php",
1617
"lint": "eslint .",
1718
"lint-fix": "eslint --fix .",
18-
"test": "ava"
19-
},
20-
"faas": {
21-
"domain": "restc",
22-
"public": "faas",
23-
"description": "A server-side middleware to visualize REST requests.",
24-
"author_name": "lujjjh",
25-
"author_email": "[email protected]",
26-
"notice": [
27-
28-
]
19+
"test": "ava",
20+
"prepack": "npm run build"
2921
},
3022
"devDependencies": {
3123
"ava": "^3.13.0",

0 commit comments

Comments
 (0)