Skip to content

Commit

Permalink
feat: serve static file
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Apr 20, 2020
1 parent 97ac345 commit 3dd1ac6
Show file tree
Hide file tree
Showing 149 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
dist
front_end
public
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"chi": "./bin/chi.js"
},
"scripts": {
"format": "prettier src/**/*.{html,js,json} *.js scripts/*.js bin/*.js server/**/*.js --write",
"format": "prettier front_end/**/*.{html,js,json} *.js scripts/*.js bin/*.js server/**/*.js --write",
"build:debug": "node scripts/build_debug"
},
"repository": {
Expand All @@ -31,6 +31,7 @@
"dependencies": {
"commander": "^5.0.0",
"koa": "^2.11.0",
"koa-router": "^8.0.8"
"koa-router": "^8.0.8",
"koa-send": "^5.0.0"
}
}
7 changes: 5 additions & 2 deletions scripts/build_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const fs = {
...require('fs').promises,
};

const pathFolders = [path.resolve(__dirname, '../src'), path.resolve(__dirname, '../devtools-frontend/front_end')];
const pathFolders = [
path.resolve(__dirname, '../front_end'),
path.resolve(__dirname, '../devtools-frontend/front_end'),
];

const outFolder = path.resolve(__dirname, '../front_end');
const outFolder = path.resolve(__dirname, '../public/front_end');

function lookupFile(fileName) {
for (const pathFolder of pathFolders) {
Expand Down
7 changes: 7 additions & 0 deletions server/middle/router.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const path = require('path');
const Router = require('koa-router');
const send = require('koa-send');

module.exports = function () {
const router = new Router();

const frontEnd = '/front_end';
router.get(`${frontEnd}/*`, async ctx => {
await send(ctx, ctx.path.slice(frontEnd.length), { root: path.resolve(__dirname, `../../public/${frontEnd}`) });
});

router.get('/', ctx => {
ctx.body = 'hello world';
});
Expand Down

0 comments on commit 3dd1ac6

Please sign in to comment.