Advertisement
Guest User

Untitled

a guest
May 10th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 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('/login', 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. res.sendFile(__dirname + '/Website/arzt.html')
  56. })
  57.  
  58. app.get('/index.html', (request, response) => {
  59. console.log("request recieved from " + request.ip + "for " + request.url)
  60. response.status(200).sendFile(__dirname + '/Website/index.html')
  61. })
  62.  
  63. app.get('/patient.html', (request, response) => {
  64. console.log("request recieved from " + request.ip + "for " + request.url)
  65. response.status(200).sendFile(__dirname + '/Website/patient.html')
  66. })
  67.  
  68. app.get('/arzt.html', (request, response) => {
  69. console.log("request recieved from " + request.ip + "for " + request.url)
  70. response.status(200).sendFile(__dirname + '/Website/arzt.html')
  71. })
  72.  
  73. app.get('/trainer.html', (request, response) => {
  74. console.log("request recieved from " + request.ip + "for " + request.url)
  75. response.status(200).sendFile(__dirname + '/Website/trainer.html')
  76. })
  77.  
  78. app.listen(port,(err) => {
  79. if(err){
  80. return console.log('something weired happened, contact Server-Admin', err);
  81. }
  82.  
  83. console.log(`server is listening @localhost:${port}`)
  84. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement