server.js 804 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. module.exports = {
  3. init: init
  4. };
  5. var express = require('express'),
  6. bodyParser = require('body-parser'),
  7. cors = require('cors'),
  8. routes = require('./routes.js');
  9. function init(hueConfig) {
  10. var app = express();
  11. app.use(express.static('frontend'));
  12. app.use(bodyParser.json());
  13. app.use(cors());
  14. app.get ('/api/config', routes.getConfig);
  15. app.get ('/api/fullState', routes.getFullState);
  16. app.get ('/api/lights', routes.getLights);
  17. app.get ('/api/lights/:id', routes.getLight);
  18. app.put ('/api/lights/:id', routes.setLight);
  19. routes.init(hueConfig, function (error) {
  20. if (error) return console.error(error);
  21. app.listen(3000, function () {
  22. console.log('Server listening on port 3000');
  23. });
  24. });
  25. }