One codebase to rule them all
Jens Vanderhaeghe - 04/06/2016
@jvanderhaeghe
jensvdh
"Isomorphic JavaScript apps are JavaScript applications that can run both client-side and server-side.
The backend and frontend share the same code."
* Also often referred to as Universal Javascript
// create new express App
let app = express();
// Set view engine to angular's express engine
app.engine('.html', expressEngine);
// when we hit request, initialize angular
app.use('/', ngApp);
// initializes Angular on the server
function ngApp(req, res) {
let baseUrl = '/';
let url = req.originalUrl || '/';
res.render('index', {
directives: [ App, ServerOnlyComponent ],
async: true,
preboot: false // { appRoot: 'app' } // your top level app component selector
});
}
// Start our Server
app.listen(3000, () => {
console.log('Listen on http://localhost:3000');
});
import 'angular2-universal-preview/polyfills';
import {prebootComplete} from 'angular2-universal-preview';
import {bootstrap} from 'angular2/platform/browser';
import {App} from './app/app.component';
bootstrap(App, [ClientOnlyComponent])
.then(prebootComplete);
We are looking for an intern: