Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. var express = require('express');
  2. var app = express();
  3.  
  4. app.use(function(req, res, next){
  5. console.log('Jestem pośrednikiem między żadaniem a odpowiedzią');
  6. next();
  7. });
  8.  
  9. app.get('/', function(req, res){
  10. console.log('Identyfikator, który został dopisany to ' + req.params.id);
  11. res.send('<form action="/post" method="post"><button>przejdź</button></form>');
  12. });
  13.  
  14. app.post('/post', function(req, res){
  15. console.log('Otrzymałem żądanie POST do strony głównej');
  16. res.send('Hello POST!');
  17. });
  18.  
  19. app.delete('/del_user', function(req, res){
  20. console.log('Otrzymałem żądanie DELETE do strony /del_user');
  21. res.send('Hello DELETE!');
  22. });
  23.  
  24. app.get('/list_user', function (req, res) {
  25. console.log('Otrzymałem żądanie GET do strony /list_user');
  26. res.send('Strona z listą użytkowników!');
  27. });
  28.  
  29. app.get('/ab*cd', function(req, res) {
  30. console.log('Otrzymałem żądanie GET do strony /ab*cd');
  31. res.send('Wzór pasuje');
  32. });
  33.  
  34. app.listen(3000);
  35.  
  36. /*var server = app.listen(3000, function(){
  37. console.log("Przykładowa aplikacja nasłuchuje na http://localhost:3000");
  38. });
  39. */
  40.  
  41. app.use(function(req, res, next) {
  42. res.status(404).send('Wybacz, nie mogliśmy odnaleźć żądanej treści');
  43. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement