Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.js 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  1. // This loads the environment variables from the .env file
  2. require('dotenv-extended').load();
  3. var express = require('express');
  4. var path = require('path');
  5. var favicon = require('serve-favicon');
  6. // Web app
  7. var app = express();
  8. var bodyParser = require('body-parser');
  9. app.use(bodyParser.json());
  10. app.use(bodyParser.urlencoded({ extended: true }));
  11. app.set('views', path.join(__dirname, 'views'));
  12. app.set('view engine', 'pug');
  13. app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  14. app.use(express.static(path.join(__dirname, 'public')));
  15. // Register your web app routes here
  16. app.get('/', function (req, res, next) {
  17. res.render('index', { title: 'Contoso Flowers' });
  18. });
  19. // Register Checkout page
  20. var checkout = require('./checkout');
  21. app.use('/checkout', checkout);
  22. // Register Bot
  23. var bot = require('./bot');
  24. app.post('/api/messages', bot.listen());
  25. // Catch 404 and forward to error handler
  26. app.use(function (req, res, next) {
  27. var err = new Error('Not Found');
  28. err.status = 404;
  29. next(err);
  30. });
  31. // Error handlers
  32. // Development error handler, will print stacktrace
  33. if (app.get('env') === 'development') {
  34. app.use(function (err, req, res, next) {
  35. res.status(err.status || 500);
  36. res.render('error', {
  37. message: err.message,
  38. error: err
  39. });
  40. });
  41. }
  42. // Production error handler, no stacktraces leaked to user
  43. app.use(function (err, req, res, next) {
  44. res.status(err.status || 500);
  45. res.render('error', {
  46. message: err.message,
  47. error: {}
  48. });
  49. });
  50. // Start listening
  51. var port = process.env.port || process.env.PORT || 3978;
  52. app.listen(port, function () {
  53. console.log('Web Server listening on port %s', port);
  54. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...