Search code examples
node.jsangularjsexpressrestify

serving a Single Page Angular App using Restify


I am new to AngularJs and wanted to start learning it. I was going to use Restify as my api/backend and was hoping it was possible to serve static files up for the route /.

app layout is something like this..

/nodesprinkler
  node_modules/
  public/
    css/
      main.css
      bootstrap.css
    js/
      angular.js
      app.js
      ...
    img/
      ...
    index.html
    favicon.ico
  server.js
  routes.js
  ...

My server.js looks like so:

var restify  = require('restify'),
    app      = module.exports = restify.createServer();

app.listen(8000, function() {
  console.log('%s listening at %s', app.name, app.url);
});

/* Client Side Route */
app.get('/', restify.serveStatic({
  directory: 'public',
  default: 'index.html'
}));

module.exports.app = app;
routes = require('./routes');

How can i get Restify to serve up my static assets so it'll work like a regular express app works? I know restify is based off express, so there must be something simple that i'm missing. It will serve up / as index.html but any of my css and js files I dont have access to.


Solution

  • try express.static()

    before app.listen put

    app.use(express.static(__dirname+"/public"))
    

    The docs