On the spot webserver

2 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€42.76
List Price:  €59.87
You save:  €17.11
£37.03
List Price:  £51.85
You save:  £14.81
CA$68.48
List Price:  CA$95.88
You save:  CA$27.39
A$75.98
List Price:  A$106.39
You save:  A$30.40
S$64.02
List Price:  S$89.63
You save:  S$25.61
HK$392.40
List Price:  HK$549.40
You save:  HK$156.99
CHF 39.80
List Price:  CHF 55.72
You save:  CHF 15.92
NOK kr506.29
List Price:  NOK kr708.85
You save:  NOK kr202.56
DKK kr318.93
List Price:  DKK kr446.53
You save:  DKK kr127.60
NZ$83.17
List Price:  NZ$116.45
You save:  NZ$33.27
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.46
৳6,077.26
List Price:  ৳8,508.66
You save:  ৳2,431.39
₹4,290.73
List Price:  ₹6,007.37
You save:  ₹1,716.63
RM212.58
List Price:  RM297.63
You save:  RM85.05
₦76,410.71
List Price:  ₦106,981.11
You save:  ₦30,570.40
₨14,215.90
List Price:  ₨19,903.40
You save:  ₨5,687.50
฿1,621.92
List Price:  ฿2,270.82
You save:  ฿648.89
₺2,008.03
List Price:  ₺2,811.40
You save:  ₺803.37
B$277.94
List Price:  B$389.15
You save:  B$111.20
R895.94
List Price:  R1,254.38
You save:  R358.44
Лв83.64
List Price:  Лв117.11
You save:  Лв33.46
₩68,944.20
List Price:  ₩96,527.40
You save:  ₩27,583.20
₪166.52
List Price:  ₪233.14
You save:  ₪66.62
₱2,823.85
List Price:  ₱3,953.62
You save:  ₱1,129.76
¥7,368.07
List Price:  ¥10,315.89
You save:  ¥2,947.82
MX$931.82
List Price:  MX$1,304.62
You save:  MX$372.80
QR181.99
List Price:  QR254.80
You save:  QR72.81
P667.26
List Price:  P934.22
You save:  P266.96
KSh6,473.70
List Price:  KSh9,063.70
You save:  KSh2,590
E£2,474.21
List Price:  E£3,464.09
You save:  E£989.88
ብር6,843.63
List Price:  ብር9,581.63
You save:  ብር2,738
Kz45,840.83
List Price:  Kz64,180.83
You save:  Kz18,340
CLP$47,851.92
List Price:  CLP$66,996.52
You save:  CLP$19,144.60
CN¥358.35
List Price:  CN¥501.72
You save:  CN¥143.37
RD$3,014.39
List Price:  RD$4,220.39
You save:  RD$1,206
DA6,486.83
List Price:  DA9,082.09
You save:  DA2,595.25
FJ$112.16
List Price:  FJ$157.03
You save:  FJ$44.87
Q383.92
List Price:  Q537.52
You save:  Q153.59
GY$10,456.33
List Price:  GY$14,639.70
You save:  GY$4,183.37
ISK kr6,089.28
List Price:  ISK kr8,525.48
You save:  ISK kr2,436.20
DH450.03
List Price:  DH630.08
You save:  DH180.05
L843.71
List Price:  L1,181.27
You save:  L337.55
ден2,632.71
List Price:  ден3,686.01
You save:  ден1,053.29
MOP$404.11
List Price:  MOP$565.78
You save:  MOP$161.67
N$886.32
List Price:  N$1,240.92
You save:  N$354.60
C$1,837.13
List Price:  C$2,572.13
You save:  C$735
रु6,855.24
List Price:  रु9,597.89
You save:  रु2,742.64
S/177.28
List Price:  S/248.21
You save:  S/70.93
K206.20
List Price:  K288.70
You save:  K82.50
SAR187.48
List Price:  SAR262.49
You save:  SAR75.01
ZK1,171.76
List Price:  ZK1,640.57
You save:  ZK468.80
L217.29
List Price:  L304.23
You save:  L86.93
Kč1,054.75
List Price:  Kč1,476.74
You save:  Kč421.98
Ft17,091.08
List Price:  Ft23,928.88
You save:  Ft6,837.80
SEK kr477.92
List Price:  SEK kr669.13
You save:  SEK kr191.20
ARS$63,089.75
List Price:  ARS$88,330.71
You save:  ARS$25,240.95
Bs346.09
List Price:  Bs484.56
You save:  Bs138.46
COP$200,628.72
List Price:  COP$280,896.26
You save:  COP$80,267.54
₡25,205.82
List Price:  ₡35,290.17
You save:  ₡10,084.34
L1,317.23
List Price:  L1,844.23
You save:  L527
₲387,342.82
List Price:  ₲542,310.94
You save:  ₲154,968.12
$U2,032.01
List Price:  $U2,844.98
You save:  $U812.96
zł182.41
List Price:  zł255.39
You save:  zł72.98
Already have an account? Log In

Transcript

When it comes to http servers, there are quite a few choices out there. Some even have their own books on configuration options. But sometimes we just want to quickly open a bare minimum HTTP server to test the piece of JavaScript code we just wrote. In this lesson, we will see how we can do exactly that. We have prepared a basic demo HTML file that contains a button, a div jQuery for helping us do some Ajax calls, and the script that will try to load static content from our server and put the content inside the deep. The script is trying to load the file on the disk such file, which is nothing more than a simple text file.

If we open this file inside our browser, we can see our page content. clicking on the button generates a JavaScript error. It is telling us that we want to do a cross origin request Which is not allowed by default by the browser. This is to prevent cross site scripting attacks. What we need to do in order to test our JavaScript code is to serve this file in our HTTP server. In order to start the HTTP server in the same folder as the file.

We type the commands on the screen. This is a basic Python module that opens Port 8000, on localhost, serving only static content. So no, you can't use it for PHP. Let's open the address in the browser. Click on the button, we see that our file content was loaded in the deep beneath the button, which means the browser is no longer blocking us because we are issuing requests by the same host using the same protocol. Looking at the output from our Python server, we can see all the requests the browser has made to the server.

We can see its request By default, a favicon dot Ico file, which doesn't exist, and it's giving back a 404 status code. You can find the files used in this project on the GitHub project page. Also, if we stop the server and go one level up and fire it up again, we can use it as a web dev server having the possibility to navigate through the files in the current directory. We could for example, give access to a folder on our local machine to a remote user and allow him or her to access it through a page in the browser, eliminating the need to install file server

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.