forked from itsky365/biturl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (19 loc) · 786 Bytes
/
Copy pathapp.js
File metadata and controls
26 lines (19 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
const Koa = require( 'koa' );
const router = require( 'koa-router' )();
const config = require( './config/custom' );
const bodyParser = require( 'koa-bodyparser' );
const Short = require( './libs/short' );
const app = new Koa();
global.logger = require( 'log4js' ).getLogger( config.host );
app.use( async(ctx, next) => {
logger.info( `[${ctx.request.method}] ${ctx.request.originalUrl} ${ctx.request.ip}` );
await next();
} );
app.use(bodyParser());
router
.get( '/', Short.index )
.get( '/:hash', Short.redirect )
.post( '/generate', Short.generate );
app.use( router.routes(), router.allowedMethods() );
module.exports = app.listen( config.port, () => logger.info( `Server running at 127.0.0.1:${config.port}` ) );