FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DefensiveCoding_JS_TreyCodingProject/main.js at main · Sandhya80/DefensiveCoding_JS_TreyCodingProject · GitHub
Sandhya80
/
DefensiveCoding_JS_TreyCodingProject
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DefensiveCoding_JS_TreyCodingProject
/
main.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (46 loc) · 1.59 KB
Breadcrumbs
DefensiveCoding_JS_TreyCodingProject
/
main.js
Copy path
File metadata and controls
52 lines (46 loc) · 1.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
calculator_callback
from
"./src/calculator.js"
;
import
linux_callback
from
"./src/linux.js"
;
import
regex_callback
from
"./src/regex.js"
;
import
express
from
"express"
;
import
fs
from
"fs"
;
import
path
from
"path"
;
const
hostname
=
"localhost"
;
const
port
=
process
.
env
.
PORT
||
4001
;
const
app
=
express
(
)
;
app
.
use
(
express
.
static
(
path
.
resolve
(
)
+
"/public"
)
)
;
app
.
get
(
"/"
,
(
request
,
response
)
=>
{
const
name
=
request
.
query
?.
fileSelector
;
let
content
=
""
;
if
(
name
)
{
if
(
name
===
"public/calculator.html"
)
{
response
.
redirect
(
"/calculator"
)
;
}
else
if
(
name
===
"public/linux.html"
)
{
response
.
redirect
(
"/linux"
)
;
}
else
if
(
name
===
"public/regex.html"
)
{
response
.
redirect
(
"/regex"
)
;
}
else
{
try
{
// Change the filePath to current working directory using the "path" method
const
filename
=
path
.
join
(
process
.
cwd
(
)
,
name
)
;
content
=
fs
.
readFileSync
(
filename
,
"utf8"
)
;
response
.
send
(
content
)
;
}
catch
(
err
)
{
response
.
status
(
404
)
;
response
.
send
(
"File not found"
)
;
}
}
}
else
{
try
{
content
=
fs
.
readFileSync
(
"public/menu.html"
,
"utf8"
)
;
}
catch
(
e
)
{
console
.
log
(
"Error:"
,
e
.
stack
)
;
}
response
.
send
(
content
)
;
}
}
)
;
app
.
get
(
'/calculator'
,
calculator_callback
)
;
app
.
get
(
'/linux'
,
linux_callback
)
;
app
.
get
(
'/regex'
,
regex_callback
)
;
app
.
listen
(
port
,
(
)
=>
{
console
.
log
(
`Server running at http://
${
hostname
}
:
${
port
}
/`
)
;
}
)
Back
|
FazBrowse Home
|
New Git URL