Skip to content

Commit

Permalink
revert: remove Front End Static
Browse files Browse the repository at this point in the history
  • Loading branch information
nusr committed Aug 9, 2019
1 parent 4864260 commit 102cb8b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 24 deletions.
3 changes: 1 addition & 2 deletions config/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import routes from './routes';
import plugins from './plugins';

// const NODE_ENV: string = process.env.NODE_ENV as string;
export default {
history: 'hash',
outputPath: 'server/dist/views',
outputPath: 'dist',
plugins,
proxy: {
'/v1': {
Expand Down
12 changes: 2 additions & 10 deletions server/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Koa from 'koa';
import _ from 'lodash';
import { Server } from 'http';
import mount from 'koa-mount'
import bodyParser from 'koa-bodyparser';
import config from './shared';
import logger from './utils/logger';
Expand All @@ -13,31 +14,22 @@ import router from './router';

import apiResponseHandler from './middleware/apiResponseHandler';

process.on('uncaughtException', e => {
logger.error(`uncaughtException: ${e}`);
});

logger.info('Comic start!');

const app: Koa = new Koa();
app.proxy = true;

app.use(errorHandler);

app.use(header);

app.use(accessControl);

app.context.debug = {
request: 0,
};

app.use(apiResponseHandler);

app.use(bodyParser());

app.use(mysql);
app.use(router.routes()).use(router.allowedMethods());
app.use(mount('/', router.routes() as Koa.Middleware)).use(router.allowedMethods());
let koaPort: number = config.serverPort;
if (process.env.NODE_ENV === 'test') {
koaPort = _.random(5000, 8000);
Expand Down
1 change: 0 additions & 1 deletion server/middleware/accessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const accessControl = async (
}

if (ctx.response.status !== statusCodes.FORBIDDEN) {
ctx.debug.request += 1;
await next();
}
}
Expand Down
9 changes: 2 additions & 7 deletions server/middleware/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import logger from '../utils/logger';

const headers = {
'Access-Control-Allow-Methods': 'GET,HEAD,PUT,POST,DELETE,PATCH',
'Content-Type': 'application/json; charset=utf-8',
};

const headerHandler = async (
Expand All @@ -13,13 +14,7 @@ const headerHandler = async (
ctx.set({
'Access-Control-Allow-Origin': `${ctx.host}`,
});
logger.info(`current request url: ${ctx.url}`);
await next();
// api request
if (ctx.state.data) {
logger.info(`current request url: ${ctx.url}`);
ctx.set({
'Content-Type': 'application/json; charset=utf-8',
});
}
};
export default headerHandler;
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"dotenv": "^8.0.0",
"koa": "2.7.0",
"koa-bodyparser": "^4.2.1",
"koa-mount": "^4.0.0",
"koa-router": "7.4.0",
"koa-static": "^5.0.0",
"lodash": "^4.17.15",
"mysql": "^2.17.1",
"pdfkit": "^0.10.0",
Expand All @@ -32,8 +32,8 @@
"@types/dotenv": "^6.1.1",
"@types/koa": "^2.0.49",
"@types/koa-bodyparser": "^4.2.2",
"@types/koa-mount": "^4.0.0",
"@types/koa-router": "^7.0.42",
"@types/koa-static": "^4.0.1",
"@types/lodash": "^4.14.136",
"@types/mysql": "^2.15.6",
"@types/node": "^12.6.9",
Expand Down
2 changes: 1 addition & 1 deletion server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ router.get('/', async (ctx: Koa.Context) => {
'Cache-Control': 'no-cache',
});
ctx.body = {
request: ctx.debug.request,
request: 'Comic Hub',
};
});

Expand Down
2 changes: 1 addition & 1 deletion server/shared/__tests__/urlConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Test Base Url', () => {
await page.goto(path, {
waitUntil: 'networkidle0',
});
await page.waitFor(2000);
await page.waitFor(1000);
const list: string[] = await page.evaluate(() => {
const arr: HTMLImageElement[] = Array.prototype.slice.apply(
document.querySelectorAll('img'),
Expand Down

0 comments on commit 102cb8b

Please sign in to comment.