I am new to koa.js library and I need help. I am trying to make a simple REST application using koa. I have static html and javascript files that I want to serve on the route / and REST API, which can be accessed from /api/ .
This is my project directory tree:
project βββ server β βββ node_modules β βββ package.json β βββ src β βββ config β βββ resources β βββ server.js βββ ui β βββ app β βββ bower.json β βββ bower_components β βββ dist β βββ node_modules β βββ package.json β βββ test
This is my source:
var app = require('koa')(); app.use(mount('/api/places', require('../resources/places'))); // does not work var staticKoa = require('koa')(); staticKoa.use(function *(next){ yield next; app.use(require('koa-static')('../ui/app', {})); }); app.use(mount('/', staticKoa)); // does not work app.use(mount('/', function*() { app.use(require('koa-static')('../ui/app/', {})); })); // does not work app.use(mount('/', function*() { app.use(require('koa-static')('.', {})); })); // GET package.json -> 404 not found
I tried the koa-static , koa-static-folder , koa-static-server libraries and didn't work, so I'm doing something wrong.
I tried this and it works, but I do not have access to my REST api:
var app = require('koa')(); app.use(require('koa-static')('../ui/app/', {}));
source share