Advertisement
Guest User

Untitled

a guest
May 9th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. /* content of server.js
  2. 1st try with simple http-module
  3. const http = require('http')
  4. const port = 1337
  5.  
  6. const requestHandler = (request, response) => {
  7. console.log('request for' + request.url)
  8. response.end('greetings from the Node.js Webserver o/')
  9. }
  10.  
  11. const server = http.createServer(requestHandler)
  12.  
  13. server.listen(port, (err) => {
  14. if(err){
  15. return console.log('something weired happened', err)
  16. }
  17.  
  18. console.log(`server ist listening @localhost:${port}`)
  19. })
  20. */
  21.  
  22. /*content of server.js
  23. 2nd try with express-framework*/
  24.  
  25. const express = require("express") //Einbindung von Express-Framework und Bindung an die express Konstante
  26. const fs = require("fs")
  27. const app = express()
  28. const port = 1337 //Webserver-Port Konstante
  29. var path = require('path')
  30. var bodyParser = require('body-parser')
  31.  
  32. app.use(express.static(path.join(__dirname)))
  33.  
  34. app.use("/styles",express.static(__dirname + "/Website/css/"))
  35. app.use("/site", express.static(__dirname + "/Website/"))
  36. app.use("/images", express.static(__dirname + "/Website/pictures/"))
  37. app.use(bodyParser.urlencoded({extended: false}));
  38. app.use(bodyParser.json())
  39. /*app.use(express.bodyParser());
  40.  
  41. app.post('/arzt.html', (req,res) => {
  42. console.console.log(req.body.use.username);
  43. console.log(req.body.use.password);
  44. })
  45. */
  46. app.get('/', (request, response) => {
  47. console.log("request recieved from " + request.ip + " for " + request.url)
  48. response.status(200).sendFile(__dirname + '/Website/index.html')
  49. })
  50.  
  51. app.post('/arzt.html', function(req,res){
  52. var user = req.body.username;
  53. var password = req.body.password;
  54. console.log("Login from " + user + ":" + password + "@localhst:1337");
  55. })
  56.  
  57. app.get('/index.html', (request, response) => {
  58. console.log("request recieved from " + request.ip + "for " + request.url)
  59. response.status(200).sendFile(__dirname + '/Website/index.html')
  60. })
  61.  
  62. app.get('/patient.html', (request, response) => {
  63. console.log("request recieved from " + request.ip + "for " + request.url)
  64. response.status(200).sendFile(__dirname + '/Website/patient.html')
  65. })
  66.  
  67. app.get('/arzt.html', (request, response) => {
  68. console.log("request recieved from " + request.ip + "for " + request.url)
  69. response.status(200).sendFile(__dirname + '/Website/arzt.html')
  70. })
  71.  
  72. app.get('/trainer.html', (request, response) => {
  73. console.log("request recieved from " + request.ip + "for " + request.url)
  74. response.status(200).sendFile(__dirname + '/Website/trainer.html')
  75. })
  76.  
  77. app.listen(port,(err) => {
  78. if(err){
  79. return console.log('something weired happened, contact Server-Admin', err);
  80. }
  81.  
  82. console.log(`server is listening @localhost:${port}`)
  83. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement