# Donejs app served from different context root?

**URL:** https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293
**Category:** DoneJS
**Created:** [June 1, 2016, 7:22pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293 "2016-06-01T19:22:04Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 1, 2016, 7:22pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/1 "2016-06-01T19:22:04Z")

</div>

I’m interested in serving my donejs app from a different base path than ‘/’, but can’t seem to find the right config setting (if any currently exists) to set that? Right now if I use nginx to proxy /foo to /, it still tries to load resources from places like ‘/dist/’ when I need them to load from ‘/foo/dist/’.

---

<div class="post-metadata">

### Author: ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)
#### Post date: [June 1, 2016, 9:58pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/2 "2016-06-01T21:58:56Z")

</div>

I think you need to configure the `root` for this.

[https://canjs.com/docs/can.route.pushstate.root.html](https://canjs.com/docs/can.route.pushstate.root.html)

Let me know if that doesn’t help.

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 1:39pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/3 "2016-06-02T13:39:41Z")

</div>

I think that should help link generation, but “done-serve” still doesn’t expose an option to run under a different root, does it?

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 1:42pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/4 "2016-06-02T13:42:49Z")

</div>

Also, that code snippet throws a null pointer error:

My app.js:

```auto
import Map from "can/map/";
import route from "can/route/";
import 'can/map/define/';
import 'can/route/pushstate/';

const AppViewModel = Map.extend({
  define: {
    title: {
      value: 'Admin',
      serialize: false
    }
  }
});

route.pushstate.root = "/admin/";
route('admin/:page', { page: 'home' });

export default AppViewModel;

```

error on `npm start`:

```auto
done-serve starting on http://localhost:8080
Potentially unhandled rejection [3] TypeError: Error loading "webadmin@0.0.0#index.stache!done-autorender@0.8.0#autorender" at file:/Users/jaredstehler/dev/src/webadmin/src/index.stache
Cannot set property 'root' of undefined
    at execute (file:/Users/jaredstehler/dev/src/webadmin/src/app.js!eval:21:28)
    at doExecute (/Users/jaredstehler/dev/src/webadmin/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:2135:22)
    at ensureEvaluated (/Users/jaredstehler/dev/src/webadmin/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:2182:11)

```

---

<div class="post-metadata">

### Author: ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)
#### Post date: [June 2, 2016, 4:12pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/5 "2016-06-02T16:12:08Z")

</div>

Ah, I’m not sure if it exposes it. However, you can use the `done-ssr-middleware` package yourself and wire it up like:

> <https://github.com/donejs/bitballs/blob/master/public/service.js>

> <https://github.com/donejs/bitballs/blob/master/index.js#L30>

@daffl @matthewp Do either of you know if can-server takes this option?

---

<div class="post-metadata">

### Author: ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)
#### Post date: [June 2, 2016, 4:12pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/6 "2016-06-02T16:12:39Z")

</div>

yikes, the docs are wrong, it should be:

`can.route.bindings.pushstate`

---

<div class="post-metadata">

### Author: ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)
#### Post date: [June 2, 2016, 4:43pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/7 "2016-06-02T16:43:27Z")

</div>

Yeah, done-serve doesn’t have such an option. I’m not sure it makes since for it to. If you have another server in front of it and are proxying /foo to done-serve’s / that should work fine. If you have a Node server then @justinbmeyer’s suggestion is the way I would go, use either done-ssr-middleware (if using Express) or done-ssr directly, that way you can control the path however you want.

On the front-end Steal should request JavaScript and CSS front whatever path it is currently at, if it is as `/foo` it should request `/foo/dist/bundles`.

It sounds maybe like you are having problems with SSR though, So i think the `renderingBaseURL` option is what you need. If you take a look at [the in-depth guide](https://donejs.com/place-my-order.html#section=section_StatichostingonFirebase__ConfiguringDoneJS) it shows what you need to do, basically:

```json
"system": {
   ...
    "envs": {
      "server-production": {
        "renderingBaseURL": "https://example.com/foo/"
      }
    }
}

```

This will cause it to render `<link>` and `<script>` urls relative to that.

Let me know if you’re having other problems.

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 6:11pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/8 "2016-06-02T18:11:53Z")

</div>

thanks, I’ll give that a shot. do I use “server-production”, or “production”, since I’m not deploying to firebase?

---

<div class="post-metadata">

### Author: ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)
#### Post date: [June 2, 2016, 6:39pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/9 "2016-06-02T18:39:36Z")

</div>

server-production. This essentially means that when done-serve is rendering, what URL does it use to render things like inside a `<link>`.

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 7:38pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/10 "2016-06-02T19:38:44Z")

</div>

Not working for me; I’ve added the following to my package.json:

```auto
    "envs": {
      "server-production": {
        "renderingBaseURL": "/admin/"
      }
    },

```

Here’s my proxy config:

```auto
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    location /admin {
       proxy_pass http://localhost:8080/;
       proxy_redirect default;
    }
}

```

Generated html for `NODE_ENV=production npm start` (using done-serve) still has:

```auto
<link rel="stylesheet" href="/dist/bundles/webadmin/index.css" asset-id="bundles/webadmin/index.css!done-css@2.0.3#css"><link rel="stylesheet" href="/dist/bundles/webadmin/home.css" asset-id="bundles/webadmin/home.css!done-css@2.0.3#css">

```

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 7:52pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/11 "2016-06-02T19:52:43Z")

</div>

So I changed the base url to an absolute one, and now many things are respecting that in the rendered output. But, my css files still aren’t rendering correctly in the html links:

```auto
<link rel="stylesheet" href="http://myapp.io/admin/bundles/webadmin/index.css" asset-id="bundles/webadmin/index.css!done-css@2.0.3#css">
<link rel="stylesheet" href="http://myapp.io/admin/bundles/webadmin/home.css" asset-id="bundles/webadmin/home.css!done-css@2.0.3#css">

```

when it should be `"/admin/dist/bundles/webadmin/home.css"`

I notice my index template has an is production check at bottom:

```auto
    {{#switch env.NODE_ENV}}
      {{#case "production"}}
        <script src="{{joinBase 'node_modules/steal/steal.production.js'}}" main="webadmin/index.stache!done-autorender"></script>
      {{/case}}
      {{#default}}
        <script src="node_modules/steal/steal.js"></script>
      {{/default}}
    {{/switch}}

```

do i need similar for top?

```auto
   <can-import from="bootstrap/less/bootstrap.less!" />
    <can-import from="webadmin/styles.less!" />
    <can-import from="webadmin/app" export-as="viewModel" />

```

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 7:54pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/12 "2016-06-02T19:54:37Z")

</div>

I’ve started from the base generator, my index stache has the following at top:

```auto
    <can-import from="webadmin/styles.less!" />
    <can-import from="webadmin/app" export-as="viewModel" />

```

I do notice that the bottom has some kind of flag for production, do I need that?

```auto

    {{#switch env.NODE_ENV}}
      {{#case "production"}}
        <script src="{{joinBase 'node_modules/steal/steal.production.js'}}" main="webadmin/index.stache!done-autorender"></script>
      {{/case}}
      {{#default}}
        <script src="node_modules/steal/steal.js"></script>
      {{/default}}
    {{/switch}}

```

---

<div class="post-metadata">

### Author: ![Jared\_Stehler](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/jared_stehler/32/280_2.png) [@Jared\_Stehler](https://forums.bitovi.com/u/Jared_Stehler)
#### Post date: [June 2, 2016, 7:55pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/13 "2016-06-02T19:55:44Z")

</div>

Do I need some kind of is production switch like I see at the bottom?

```auto

    {{#switch env.NODE_ENV}}
      {{#case "production"}}
        <script src="{{joinBase 'node_modules/steal/steal.production.js'}}" main="webadmin/index.stache!done-autorender"></script>
      {{/case}}
      {{#default}}
        <script src="node_modules/steal/steal.js"></script>
      {{/default}}
    {{/switch}}

```

currently at top is:

```auto
    <can-import from="bootstrap/less/bootstrap.less!" />
    <can-import from="webadmin/styles.less!" />
    <can-import from="webadmin/app" export-as="viewModel" />

```

---

<div class="post-metadata">

### Author: ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)
#### Post date: [June 3, 2016, 1:31pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/14 "2016-06-03T13:31:48Z")

</div>

Did you change the renderingBaseURL to `http://myapp.io/admin/`?

---

<div class="post-metadata">

### Author: ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)
#### Post date: [June 3, 2016, 1:32pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/15 "2016-06-03T13:32:23Z")

</div>

Going to see if I can recreate the issue in done-css.

---

<div class="post-metadata">

### Author: ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)
#### Post date: [June 3, 2016, 2:04pm UTC](https://forums.bitovi.com/t/donejs-app-served-from-different-context-root/293/16 "2016-06-03T14:04:38Z")

</div>

I’m seeing the same thing in an app @Jared_Stehler.

Can you change the renderingBaseURL to `http://myapp.io/admin/dist/`. I’ll have to think about it some more, but this might be correct behavior. This is how CDN deployments work as well, the dist folder is your renderingBaseURL.

But `/admin/` is not working and I’m not sure why, filed a bug here: [https://github.com/donejs/css/issues/44](https://github.com/donejs/css/issues/44)

I can’t remember if this was done on purpose or not, looking into it.
