server.js 564 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. module.exports = {
  3. init: init
  4. };
  5. var express = require('express'),
  6. bodyParser = require('body-parser'),
  7. routes = require('./routes.js');
  8. function init(hueConfig) {
  9. var app = express();
  10. app.use(bodyParser.json());
  11. app.get ('/api/lights', routes.getLights);
  12. app.post('/api/lights/:id', routes.setLight);
  13. routes.init(hueConfig, function (error) {
  14. if (error) return console.error(error);
  15. app.listen(3000, function () {
  16. console.log('Server listening on port 3000');
  17. });
  18. });
  19. }