Difficulty using seperate template files in ember router with browserify - node.js

I've followed this tutorial http://kroltech.com/2013/12/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/ to set up my backend node.js server, but instead of using backbone-marionette for the frontend I want to try ember. Therefore, having successfully set up the server, I am now going through this tutorial for ember http://emberjs.com/guides/getting-started/.
The problem I'm running into is including external templates into my ember routes. With this code and the todos template written in the browser the app works fine.
var Ember = require('ember');
window.Todos = Ember.Application.create();
Todos.Router.map(function() {
this.resource('todos', { path: '/' });
});
However, with a template written in ./templates/application.hbs and using browserify to try this,
Todos.Router.map(function() {
this.resource(require('./templates/application.hbs'), { path: '/' });
});
I get the errors shown below.
Uncaught TypeError: undefined is not a function myapp.js:46841
Error: Assertion Failed: The URL '/' did not match any routes in your application
at new Error (native)
at Error.Ember.Error (http://localhost:3300/js/myapp.js:12978:19)
at Object.Ember.assert (http://localhost:3300/js/myapp.js:12141:11)
at http://localhost:3300/js/myapp.js:47347:15
at invokeCallback (http://localhost:3300/js/myapp.js:22081:19)
at publish (http://localhost:3300/js/myapp.js:21751:9)
at publishRejection (http://localhost:3300/js/myapp.js:22179:7)
at http://localhost:3300/js/myapp.js:30448:7
at Object.DeferredActionQueues.flush (http://localhost:3300/js/myapp.js:18195:24)
at Object.Backburner.end (http://localhost:3300/js/myapp.js:18283:27) myapp.js:15589
Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/' did not match any routes in your application
I was hoping someone could shed some light on how to include external templates in an ember router. Thanks!

Thanks for looking into it! I think I did a poor job explaining my question - I understood that it was the template name but I didn't understand how to include that in my application. I searched around a bit more and found grunt-ember-templates.
For future reference, they have really good docs to get you set up, this is what my emberTemplates code looked like.
emberTemplates: {
compile: {
options: {
templateBasePath: 'client/src/templates'
},
files: {
'build/templates.js': ['client/src/templates/*.hbs']
}
}
},
And then I just added 'application' as my route template name.
Don't forget to compile all of build/ in your app build.

Related

Node webpack dev server failing 'Cannot GET /' in vuejs project

I am getting a super unhelpful message 'Cannot GET /' printed to my browser when I run my node dev server through webpack. I am building a Vuejs application with the following:
VueJs structured in a way that was dicated by this Vue Template with my node scripts being identical to the default commands
Webpack config based on Vue Loader
Routes handled through Vue Router
I know this is not a great deal to go off but an idea of what is firing this error (Node? Webpack? Vue Router?) it would point me in the right direction and be greatly appreciated.
If you're experiencing this with Vite, make sure you ran just vite in your package.json script, NOT vite preview
I found myself in the same problem. In my case it was related to the use of Express with Vue.js. So I am leaving my solution in case anyone finds it useful
I added this code for handling the calls to my index.html file
app.route('/*')
.get(function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
module.exports = app;
Node is throwing the error and make sure your vue router is configured properly,Cannot GET simply means you have not assigned a view to your url e.g on express we use
app.use('/', your route)
and on connect we use
app.get or app.post
All it's saying is there is no content/view assigned to that url.
It turns out it was an issue with the vuejs webpack template I was working from: https://github.com/vuejs-templates/webpack
The build path was being used in the dev server configuration.
Made this pull request to fix the issue: https://github.com/vuejs-templates/webpack/pull/188#issuecomment-230968416
I had this issue while running my app in dev. Adding this to the devServer of my webpack.dev.config file helped:
historyApiFallback: true
Answer by Jezperp here.
If you are using express check that you have this line:
app.use(express.static('static'));
And that "static" matches with the folder specified in your vue.config.js
outputDir: path.resolve("../Server/static")

Nodejs/apidocjs: How do I render the generated documentation at a specific url without a template

I am writing apidocs for a nodejs project someone else wrote.
I would like the documentation page to be displayed when someone visits "myurl.com/docs/api". My documentation directory is being placed under "app/public/app/docs/apidoc/" and I am trying to use routes to display it but gives me an error stating:
'Error: Failed to lookup view "/public/app/apidoc/index.html" in views directory "/Path/To/Project/app/views"'
Here is my routes.js entry:
app.get('/docs/api', function(req, res) {
res.render('/app/apidoc/index.html');
});
I believe the project uses jade and ejs as they are listed somewhere in the configuration files.
You can serve the documentation from the public folder by using this
app.use(express.static('public'));
And then generate the apidoc with this command
apidoc -e "(node_modules|public)" -o public/apidoc
Now you can access the documentation by navigating to http://{rooturl}/apidoc

Angular / Express hosting

I want to run angular on a linux box without needing node or express. I've created a website but not sure what tech is what, haha. I'm assuming I have a simple web server using express server, see code below.
var express = require ('express');
var app = express();
var path = require('path');
app.use(express.static(__dirname + '/'));
app.listen(8080);
console.log('Magic happens on port 8080');
I start this using the node server command. And the rest of the code is angular-ui.
Do I need to use express (and host this on a node compatible server), or can I just run this thing on a linux box without express? If so, do i need to replace my server.js file (above) with something else? or... Currently it's not working on the linux box, but works locally just fine.
**Edit: I tested an angular 'hello world' app on my shared server, it worked fine. When I run the full angular app on the shared server I get the following error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module routerApp due to:
Error: [$injector:nomod] Module 'routerApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
** edit: In answer to #RobertMoskal 's question below, the angular hello world test that's working on the shared server is basically this:
<input ng-model="name" type="text" placeholder="Type a name here">
<h1>Hello {{ name }}</h1>
And the real app is basically something like this, using ui-view and ng-repeat in the html:
var routerApp = angular.module('routerApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/home');
$locationProvider.html5Mode(false).hashPrefix("");
$stateProvider
// HOME STATES AND NESTED VIEWS ========================================
.state('home', {
url: '/home',
templateUrl: 'partial-home.html',
// onEnter: scrollContent
})
// ANIMATION AND NESTED VIEWS ========================================
.state('animation', {
url: '/animation',
templateUrl: 'partial-anim.html',
controller: function($scope) {
$scope.animations = [
{ title:'One', url:'http://yahoo.com', bg:'#f8f8f8', width:'160', height:'600', imageAsset:'assets/imgs/web/MyWebsites_1.jpg', paragraph:'some text of some description'},
{ title:'Two', url:'http://google.com', bg:'#f8f8f8', width:'160', height:'600', imageAsset:'assets/imgs/web/MyWebsites_2.jpg', paragraph:'rabbit rabbit rabbit'},
{ title:'Three', url:'http://bambam.com', bg:'#f8f8f8', width:'160', height:'600', imageAsset:'assets/imgs/web/MyWebsites_3.jpg', paragraph:'blahiblahblah'}];
}
})
// GAME VIEWS ========================================
.state('game', {
url: '/game',
templateUrl: 'partial-game.html'
})
// CONTACT VIEWS ========================================
.state('contact', {
url: '/contact',
templateUrl: 'partial-contact.html'
})
});
You need some web server to server your angular app as a "static" asset. This can be apache or nginx or any number of web servers. Most linux distributions make it easy to install them.
You can also go super lightweight with the built in python web server:
cd /var/www/
$ python -m SimpleHTTPServer
You can even host your application for free on github.
In all cases you you just need to make sure that the web server is serving your assets from the correct path. The above python example example you might have your app entry point in /var/www/index.html and it would be served as http://localhost:8000/index.html.

Configure Bower with Sails.js 0.10

I installed grunt-bower module and followed up the below link:
https://stackoverflow.com/a/22456574/194345
but still not able to access js or css files placed in assets folder.
I installed jquery with bower which is in "assets\lib\jquery\dist\jquery.js" but in browser, tried following URL to access it:
http://localhost:1337/js/jquery.js
http://localhost:1337/lib/js/jquery.js
http://localhost:1337/lib/jquery/dist/jquery.js
it always displays not found.
What is the correct path?
I think you may not have fully implemented the solution from the link you posted, specifically the part about configuring the grunt-bower task. I've edited that otherwise excellent answer to be a but more clear--you need to wrap the configuration in a function and save it as tasks/config/bower.js:
module.exports = function(grunt) {
grunt.config.set('bower', {
dev: {
dest: '.tmp/public',
js_dest: '.tmp/public/js',
css_dest: '.tmp/public/styles'
}
});
grunt.loadNpmTasks('grunt-bower');
};
Then, next time you lift Sails, jquery.js will be copied to .tmp/public/js and therefore be available at http://localhost:1337/js/jquery.js.

Reference Socket.io fron Node server in Offline App with Require.js

I am trying to use Socket.io hosted by a Node server. I am using Require.js to manage dependencies. My webapp is Offline capable.
When the webapp is offline, and cannot contact the node server, require.js throws an error because it cannot find the socket.io dependency.
GET http://mikemac.local:8000/socket.io/socket.io.js  require.js:33
Uncaught Error: Script error
http://requirejs.org/docs/errors.html#scripterror
In this case I am not using node/io for the majority of the system, just 'bonus' real time notifications. So The app should run without it.
How can I deal with this? I would like a way to detect that it cannot be found and then disable the socket.io functionality until a connection/refresh attempt.
In your configuration setup fallback to other module and in the fallback indicate that it is offline:
requirejs.config({
enforceDefine: true,
paths: {
socketio: [
'http://mikemac.local:8000/socket.io/socket.io',
//If the CDN location fails, load from this location
'lib/socketoffline'
]
}
});
//socketoffline
define({ offline: true});
//Later
require(['socketio'], function (socketio) {
if (socketio.offline){
// your library did not load:
} else {
// socketio loaded
}
});

Resources