forked from libreirc/libreirc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request libreirc#5 from openirc/koa
기본 koa 서버 세팅
- Loading branch information
Showing
4 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
/server/node_modules/ | ||
/server/dist/ | ||
/server/public/build/ | ||
|
||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }`); | ||
} | ||
} | ||
} |