diff --git a/.gitignore b/.gitignore index 32d3632..4edc5a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /server/node_modules/ /server/dist/ /server/public/build/ + +npm-debug.log diff --git a/README.md b/README.md index 931b36f..1853e77 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/server/package.json b/server/package.json index a747fb2..420f024 100644 --- a/server/package.json +++ b/server/package.json @@ -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" } } diff --git a/server/src/main.js b/server/src/main.js index 426f8b0..d2b6c38 100644 --- a/server/src/main.js +++ b/server/src/main.js @@ -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 }`); + } + } +}