Skip to content

Commit

Permalink
Merge pull request libreirc#5 from openirc/koa
Browse files Browse the repository at this point in the history
기본 koa 서버 세팅
  • Loading branch information
simnalamburt authored Nov 5, 2016
2 parents 7932465 + e607873 commit 7f15f31
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/server/node_modules/
/server/dist/
/server/public/build/

npm-debug.log
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ npm run watch # Run webpack in watch mode
# Running server
cd server

npm install # Install dependencies
npm test # Static type checking (flow)
npm run build # Build everything in production mode (flow + babel)
npm install # Install dependencies
npm test # Static type checking (flow)
npm run build # Build everything in production mode (flow + babel)

npm run watch # Run babel in watch mode
npm start # Start the server
npm run watch # Run babel in watch mode
npm start [port] # Start the server. Default port is 4321
```

### Directory structure
Expand Down
5 changes: 5 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
"babel-preset-flow": "^0.1.1",
"babel-preset-stage-3": "^6.5.0",
"flow-bin": "^0.23.1"
},
"dependencies": {
"koa": "^2.0.0",
"koa-router": "^7.0.1",
"koa-send": "^3.2.0"
}
}
35 changes: 33 additions & 2 deletions server/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
// @flow

let hello: string = 'Hello, world!';
console.log(hello);
import path from 'path';
import os from 'os';

import Koa from 'koa';
import send from 'koa-send';
import koaRouter from 'koa-router';


const port: number = parseInt(process.argv[2]) || 4321;
const app = new Koa();
const router = koaRouter();

const publicDirectory: string = path.join(__dirname, '../public');

router.get('/', async ctx => {
await send(ctx, 'index.html', { root: publicDirectory });
});
router.get('*', async ctx => {
await send(ctx, ctx.path, { root: publicDirectory });
});
app.use(router.routes());

app.listen(port);

console.log('OpenIRC server is available on:');
const ifaces = os.networkInterfaces();
for (let device of Object.keys(ifaces)) {
for (let details of ifaces[device]) {
if (details.family === 'IPv4') {
console.log(` http://${ details.address }:${ port }`);
}
}
}

0 comments on commit 7f15f31

Please sign in to comment.