Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최은석
/
ossw-project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
채지성
2022-05-10 23:30:39 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2819674256ccedc861a18addf72ed657ba8af7e4
28196742
1 parent
6799f5f6
third
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
14 deletions
server.js
static/index.ejs
server.js
View file @
2819674
...
...
@@ -2,30 +2,39 @@
const
express
=
require
(
'express'
);
const
app
=
express
();
const
ejs
=
require
(
'ejs'
);
app
.
set
(
'view engine'
,
'ejs'
);
app
.
set
(
'views'
,
'./static'
);
const
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
express
.
json
());
app
.
listen
(
8080
,
function
()
{
console
.
log
(
'listening on 8080'
)
})
app
.
get
(
'/'
,
function
(
req
,
res
){
res
.
render
(
'index.ejs'
,
{
items
:
items
});
})
let
items
=
[];
app
.
get
(
'/'
,
function
(
req
,
res
){
res
.
send
(
items
);
});
app
.
post
(
'/post'
,
function
(
req
,
res
){
let
item
=
req
.
body
.
text
;
console
.
log
(
item
);
if
(
item
!=
""
){
items
.
push
(
item
);}
console
.
log
(
"items"
,
items
);
let
item
=
req
.
body
;
console
.
log
(
item
.
id
);
console
.
log
(
item
.
text
);
if
(
item
!=
""
){
items
.
push
(
item
);
}
console
.
log
(
"items: "
,
items
);
res
.
send
(
items
);
});
app
.
delete
(
'/item/:id'
,
function
(
req
,
res
){
let
id
=
req
.
params
.
id
;
console
.
log
(
id
);
res
.
render
(
'index.ejs'
,
{
items
:
items
});
items
.
forEach
((
elem
,
index
)
=>
{
if
(
elem
.
id
==
id
){
items
.
splice
(
index
,
1
);
}
});
console
.
log
(
items
);
res
.
send
(
items
);
});
\ No newline at end of file
...
...
static/index.ejs
View file @
2819674
...
...
@@ -9,7 +9,13 @@
<button
type=
"submit"
>
submit
</button>
</form>
<
% items.forEach(function(item){ %>
<div>
<p>
<
%= item %>
</p></div>
<form
action=
"/post2"
method=
"post"
>
<div>
<p>
<
%= item %>
</p>
<input
type=
"hidden"
value=
"<%= item %>"
name=
"value"
>
<button
type=
"submit"
>
submit
</button>
</div>
</form>
<
% }); %>
</body>
...
...
Please
register
or
login
to post a comment