Hello Ember community.
I am new to Ember after deciding Angular 2 is too freaking weird and unattractive.
I am developing a full-stack app using Ember and Express.
My file structure
(This is inside the main project folder)
- client (made from ember-cli generator)
- server (server routes, etc.)
- api (api routes)
- server.js (use command
node server.js
to start)
Plus some additional top-level server stuff.
How am I working with my own REST API and serving Ember files?
Server.js
//server.js
...
////////////////////////////////////////////////////////
// Init routes //
// APIs *MUST* be declared first, as everything after //
// will render Ember client code. //
////////////////////////////////////////////////////////
// Allows call to my REST API
require('./api/core')(server);
// Now set server to look at generated ember client files
server.use(express.static(__dirname + '/client/dist'));
server.use('/', require('./server/routes'));
...
/server/routes.js
//routes.js
...
// Location to built dist by Ember
var rootPath = './client/dist/';
// Route ALL locations to index.html, the main Ember app
router.get('*', function(request, response) {
// Send index.html
response.sendFile('index.html', { root: rootPath });
});
module.exports = router;
...
I think the key part is that everything works. I tested my API, which returns successfully. I also tested going to /
(index) and /about
(sample about page to test a non-index route). Both work as intended.
tl;dr So the question is: is this the proper way to be doing things with Ember and Express?
From my point of view, it appears that I have the “middle” set up and can begin developing the front-end (Ember) and backend (REST API) separately, as intended.