diff --git a/app.js b/app.js new file mode 100644 index 0000000..42690e5 --- /dev/null +++ b/app.js @@ -0,0 +1,25 @@ +const Koa = require('koa'); +const cors = require('@koa/cors'); +const app = new Koa(); + + + +app.use(cors()); +/* + * Define route handler(s): + * + * This means we connect HTTP methods: GET, POST, ... + * and URI paths: /some/uri/path + * to JavaScript functions that handle the request. + * + * Once defined we then add them to the app object. +*/ + +const users = require('./routes/users.js'); +const applications = require('./routes/applications.js'); +app.use(users.routes()); +app.use(applications.routes()); + +let port = process.env.PORT || 3000; + +app.listen(port); diff --git a/index.js b/index.js index 42690e5..6381bb5 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,4 @@ -const Koa = require('koa'); -const cors = require('@koa/cors'); -const app = new Koa(); - - - -app.use(cors()); -/* - * Define route handler(s): - * - * This means we connect HTTP methods: GET, POST, ... - * and URI paths: /some/uri/path - * to JavaScript functions that handle the request. - * - * Once defined we then add them to the app object. -*/ - -const users = require('./routes/users.js'); -const applications = require('./routes/applications.js'); -app.use(users.routes()); -app.use(applications.routes()); - +const app = require('./app'); let port = process.env.PORT || 3000; - app.listen(port); +console.log(`API server running on port ${port}`) \ No newline at end of file