Skip to content

Commit

Permalink
release: v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jul 21, 2022
1 parent f23dc51 commit d66eaf5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.0 (21 Jul 2022)

* feat: support cdn option

## 1.1.0 (21 Jul 2022)

* feat: cdn for embedded mode
Expand Down
4 changes: 3 additions & 1 deletion bin/chii.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ program
.option('-p, --port <port>', 'set the port to start on. defaults to 3000', parseInt)
.option('-h, --host <host>', 'set the host. defaults to 0.0.0.0')
.option('-d, --domain <domain>', 'set the domain. defaults to localhost:port')
.action(({ port, host, domain }) => {
.option('--cdn <cdn>', 'use cdn like jsdelivr')
.action(({ port, host, domain, cdn }) => {
server.start({
port,
host,
domain,
cdn,
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chii",
"version": "1.1.0",
"version": "1.2.0",
"description": "Chrome devtools framework",
"main": "./server/index.js",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const compress = require('./middle/compress');
const util = require('./lib/util');
const WebSocketServer = require('./lib/WebSocketServer');

function start({ port = 8080, host, domain, server } = {}) {
function start({ port = 8080, host, domain, server, cdn } = {}) {
domain = domain || 'localhost:' + port;

const app = new Koa();
const wss = new WebSocketServer();

app.use(compress()).use(router(wss.channelManager, domain));
app.use(compress()).use(router(wss.channelManager, domain, cdn));

if (server) {
server.on('request', app.callback());
Expand Down
11 changes: 10 additions & 1 deletion server/middle/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const pkg = require('../../package.json');

const maxAge = ms('2h');

module.exports = function (channelManager, domain) {
module.exports = function (channelManager, domain, cdn) {
const router = new Router();

router.get('/', async ctx => {
Expand All @@ -31,6 +31,15 @@ module.exports = function (channelManager, domain) {
});
});

if (cdn) {
router.get('/front_end/chii_app.html', async ctx => {
const tpl = await readTpl('chii_app');
ctx.body = tpl({
cdn,
});
});
}

let timestamp = now();
router.get('/timestamp', ctx => {
ctx.body = timestamp;
Expand Down
14 changes: 14 additions & 0 deletions server/tpl/chii_app.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>DevTools</title>
<style>
@media (prefers-color-scheme: dark) {
body {
background-color: rgb(41 42 45);
}
}
</style>
<meta name="referrer" content="no-referrer">
<script type="module" src="{{cdn}}/front_end/entrypoints/chii_app/chii_app.js"></script>
<body class="undocked" id="-blink-dev-tools">
4 changes: 3 additions & 1 deletion src/DevtoolsFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import evalCss from 'licia/evalCss';
import toStr from 'licia/toStr';
import toNum from 'licia/toNum';
import startWith from 'licia/startWith';
import isStr from 'licia/isStr';
import isJson from 'licia/isJson';

const $document = $(document as any);

Expand Down Expand Up @@ -92,7 +94,7 @@ export default class DevtoolsFrame {
if (event.origin !== targetOrigin) {
return;
}
if (event.data) {
if (event.data && isStr(event.data) && isJson(event.data)) {
chobitsu.sendRawMessage(event.data);
}
});
Expand Down

0 comments on commit d66eaf5

Please sign in to comment.