Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3. const cors = require('cors');
  4. const r = require('rethinkdbdash')({ db: 'tm_tieto' });
  5.  
  6. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  7.  
  8. const settings = {
  9. secret: 'd7cad03d66f2d263991b2412dc112b7e',
  10. site: {
  11. name: 'Tm-Tieto Oy',
  12. url: 'http://localhost:3000'
  13. },
  14. email: {
  15. from: "no-reply@tm-tieto.fi",
  16. host: "mail.smtp2go.com",
  17. user: "test@email.com",
  18. password: "azFjM3BkbjhzcDAw",
  19. ssl: true
  20. }
  21. };
  22.  
  23. const app = express();
  24. app.use(cors());
  25. app.use(bodyParser.json())
  26. .use(bodyParser.urlencoded({ extended: false }));
  27.  
  28. const auth = require('chaos-auth')(r, settings);
  29. const apiRoutes = express.Router();
  30.  
  31. app.use('/auth', auth.router);
  32.  
  33. app.get('/test', auth.authorize, (req, res) => {
  34. console.log('test works');
  35. res.send({ success: true, message: 'i am authorized' });
  36. });
  37.  
  38. require('./controllers/assets')(r, apiRoutes, auth);
  39. require('./controllers/environment_cards')(r, apiRoutes, auth);
  40. require('./controllers/customer_types')(r, apiRoutes, auth);
  41. require('./controllers/users')(r, apiRoutes, auth);
  42. require('./controllers/organizations')(r, apiRoutes, auth);
  43. app.use('/v1', apiRoutes);
  44.  
  45. // Basic Request Logger
  46. app.use((req, res, next) => {
  47. console.log(new Date(), req.method, req.path);
  48. next();
  49. });
  50.  
  51. // Attach your endpoints/controllers here
  52. app.listen(3000, () => {
  53. console.log(`The API is running on port 3000`);
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement