Skip to content

Instantly share code, notes, and snippets.

@neomadara
Forked from jrmoran/public-app.js
Last active May 23, 2016 17:12
Show Gist options
  • Save neomadara/f3f62bb55baa6d61a2968dd9c537e774 to your computer and use it in GitHub Desktop.
Save neomadara/f3f62bb55baa6d61a2968dd9c537e774 to your computer and use it in GitHub Desktop.
AngularJS and Express, rendering ejs-locals partials
var app = angular.module('app', ['ngResource']);
app.config(function($locationProvider, $routeProvider) {
// $locationProvider.html5Mode(true);
$routeProvider
.when('/', { templateUrl: 'partials/index', controller: 'ctrl' })
.when('/about', { templateUrl: 'partials/about', controller: 'ctrl' })
.otherwise({redirectTo:'/'});
});
app.controller('ctrl', function($scope){});
exports.index = (req, res)->
res.render 'index', message:"Hello!!!"
exports.partials = (req, res)->
filename = req.params.filename
return unless filename # might want to change this
res.render "partials/#{filename}"
express = require 'express'
routes = require './routes'
engine = require 'ejs-locals'
app = express()
app.engine('ejs', engine)
app.set('view engine', 'ejs')
app.set('views', __dirname + '/views')
app.use(express.static __dirname + '/public')
app.get('/partials/:filename', routes.partials)
app.use(routes.index) # everything else
app.listen 3000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Test</title>
<script src="components/angular-complete/angular.js"
type="text/javascript"></script>
<script src="components/angular-complete/angular-resource.js"
type="text/javascript"></script>
<script src="app.js"
type="text/javascript"></script>
</head>
<body ng-app='app'>
<%- message %>
<a href="#/about"> /about</a> |
<a href="#/"> home</a>
<!-- uncomment if HTML5Mode on -->
<!-- <a href="/about"> /about</a> | -->
<!-- <a href="/"> home</a> -->
<hr />
<div ng-view></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment