Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. var express = require('express')
  2. var app = express()
  3.  
  4. app.set('port', (process.env.PORT || 5000))
  5. app.use(express.static(__dirname + '/public'))
  6.  
  7. function getRandomInt(min, max) {
  8. return Math.floor(Math.random() * (max - min + 1)) + min;
  9. }
  10.  
  11. app.get('/products', function(request, response) {
  12.  
  13. response.header("Access-Control-Allow-Origin", "*");
  14. response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  15. var option = getRandomInt(0,5);
  16. if (option < 4) {
  17. var products = {
  18. 'KeyboardCombo' : {
  19. price : getRandomInt(25,35),
  20. quantity : getRandomInt(0,10),
  21. url : 'https://cpen400a.herokuapp.com/images/KeyboardCombo.png'
  22. },
  23. 'Mice' : {
  24. price : getRandomInt(5,7),
  25. quantity : getRandomInt(0,10),
  26. url : 'https://cpen400a.herokuapp.com/images/Mice.png'
  27. },
  28. 'PC1' : {
  29. price : getRandomInt(300,350),
  30. quantity : getRandomInt(0,10),
  31. url : 'https://cpen400a.herokuapp.com/images/PC1.png'
  32. },
  33. 'PC2' : {
  34. price : getRandomInt(350,400),
  35. quantity : getRandomInt(0,10),
  36. url : 'https://cpen400a.herokuapp.com/images/PC2.png'
  37. },
  38. 'PC3' : {
  39. price : getRandomInt(330,380),
  40. quantity : getRandomInt(0,10),
  41. url : 'https://cpen400a.herokuapp.com/images/PC3.png'
  42. },
  43. 'Tent' : {
  44. price : getRandomInt(30,40),
  45. quantity : getRandomInt(0,10),
  46. url : 'https://cpen400a.herokuapp.com/images/Tent.png'
  47. },
  48. 'Box1' : {
  49. price : getRandomInt(5,7),
  50. quantity : getRandomInt(0,10),
  51. url : 'https://cpen400a.herokuapp.com/images/Box1.png'
  52. },
  53. 'Box2' : {
  54. price : getRandomInt(5,7),
  55. quantity : getRandomInt(0,10),
  56. url : 'https://cpen400a.herokuapp.com/images/Box2.png'
  57. },
  58. 'Clothes1' : {
  59. price : getRandomInt(20,30),
  60. quantity : getRandomInt(0,10),
  61. url : 'https://cpen400a.herokuapp.com/images/Clothes1.png'
  62. },
  63. 'Clothes2' : {
  64. price : getRandomInt(20,30),
  65. quantity : getRandomInt(0,10),
  66. url : 'https://cpen400a.herokuapp.com/images/Clothes2.png'
  67. },
  68. 'Jeans' : {
  69. price : getRandomInt(30,40),
  70. quantity : getRandomInt(0,10),
  71. url : 'https://cpen400a.herokuapp.com/images/Jeans.png'
  72. },
  73. 'Keyboard' : {
  74. price : getRandomInt(15,25),
  75. quantity : getRandomInt(0,10),
  76. url : 'https://cpen400a.herokuapp.com/images/Keyboard.png'
  77. }
  78. };
  79.  
  80. response.json(products);
  81. } else if (option == 4) {
  82. response.status(500).send("An error occurred, please try again");
  83. }
  84. })
  85.  
  86. app.listen(app.get('port'), function() {
  87. console.log("Node app is running at localhost:" + app.get('port'))
  88. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement