Giter VIP home page Giter VIP logo

Comments (10)

babnik63 avatar babnik63 commented on August 20, 2024

I have the same problem
I need to separate my koa app files and I don't know how to mount them from different paths.

from mount.

jonathanong avatar jonathanong commented on August 20, 2024
var subapp1 = require('./subapp1')
var subapp2 = require('./subapp2')

app.use(mount('/subapp1', subapp1))
app.use(mount('/subapp2', subapp2))

your questions need more code because right now it's ambiguous

from mount.

MBehtemam avatar MBehtemam commented on August 20, 2024

@jonathanong according to your solution this is app1 but when in my server.js that is my startup app i call this var app = require('./Client/Applications/sandbox'); the home of app1 and then NAP.use(mount('/app',app)); but i get this error :

NAP Listen ON 127.0.0.1:3000
TypeError: Object #<Object> has no method 'call'
at Object.<anonymous> (G:\NAP\node_modules\koa-mount\index.js:51:22)
at GeneratorFunctionPrototype.next (native)
at next (G:\NAP\node_modules\koa\node_modules\co\index.js:70:21)
at Object.<anonymous> (G:\NAP\node_modules\koa\node_modules\co\index.js:50:5)
at next (G:\NAP\node_modules\koa\node_modules\co\index.js:86:21)
at Object.<anonymous> (G:\NAP\node_modules\koa\node_modules\co\index.js:50:5)
at next (G:\NAP\node_modules\koa\node_modules\co\index.js:86:21)
at Object.<anonymous> (G:\NAP\node_modules\koa\node_modules\co\index.js:50:5)
at next (G:\NAP\node_modules\koa\node_modules\co\index.js:86:21)
at Object.<anonymous> (G:\NAP\node_modules\koa\node_modules\co\index.js:50:5)

from mount.

jonathanong avatar jonathanong commented on August 20, 2024

still need a test case. looks like you're not passing an app

from mount.

MBehtemam avatar MBehtemam commented on August 20, 2024

Ok. this is my App

from mount.

jonathanong avatar jonathanong commented on August 20, 2024

if i can't copy and paste it then it's not a test case

from mount.

MBehtemam avatar MBehtemam commented on August 20, 2024

Ok .
This is App.js :

var koa = require('koa'),
fs = require('fs'),
views = require('koa-render'),
router = require('koa-route'),
hbs = require('koa-hbs'),
mount= require('koa-mount'),
path = require('path'),
serve = require('koa-static'),
AppConfing = JSON.parse(fs.readFileSync('./config/NAPConfig.json')),
App = koa();

  //Requiring Some App for mounting 
   var app = require('./Client/Applications/sandbox');

App.use(mount('/app',app));
App.listen(AppConfing.hostPort,AppConfing.hostIp,function(){
console.log("App Listen ON " + AppConfing.hostIp + ":" + AppConfing.hostPort);
});

App.listen(3000);

and this is App1 :

var koa  = require('koa'),
route = require('koa-route'),
app = koa();

  app.use(route.get('/',function *(){
this.body = "HELLO WORLD";
}));

tnx

from mount.

jonathanong avatar jonathanong commented on August 20, 2024

you're not exporting the app. that's it.

from mount.

MBehtemam avatar MBehtemam commented on August 20, 2024

In App :

module.exports = {
var koa  = require('koa'),
route = require('koa-route'),
app = koa();

  app.use(route.get('/',function *(){
this.body = "HELLO WORLD";
}));

 }

and this is the error :

 G:\NAP\Client\Applications\sandbox\index.js:2
    var koa  = require('koa'),
        ^^^
  SyntaxError: Unexpected identifier
  at exports.runInThisContext (vm.js:69:16)
  at Module._compile (module.js:432:25)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:349:32)
  at Function.Module._load (module.js:305:12)
  at Module.require (module.js:357:17)
  at require (module.js:373:17)
  at Object.<anonymous> (G:\NAP\app.js:17:11)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)

i think it cant load koa

from mount.

MBehtemam avatar MBehtemam commented on August 20, 2024

OOPS . if find my mistake.

var koa  = require('koa'),
route = require('koa-route'),
app = koa();

 app.use(route.get('/',function *(){
this.body = "HELLO WORLD";
}));

module.exports = app;

from mount.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.