Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Wighus Holtmon
PROG2053-Project
Commits
fe8d33e0
Commit
fe8d33e0
authored
Nov 12, 2021
by
Martin Wighus Holtmon
Browse files
projectSecondPart/Problem2 - Setup express server
parent
90b98584
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
projectSecondPart/package-lock.json
View file @
fe8d33e0
This diff is collapsed.
Click to expand it.
projectSecondPart/package.json
View file @
fe8d33e0
...
...
@@ -2,10 +2,13 @@
"name"
:
"part2"
,
"version"
:
"0.1.0"
,
"scripts"
:
{
"start"
:
"react-scripts start"
"start"
:
"react-scripts start"
,
"start-express"
:
"nodemon webServer.js"
},
"dependencies"
:
{
"@material-ui/core"
:
"^4.12.3"
,
"express"
:
"^4.17.1"
,
"nodemon"
:
"^2.0.15"
,
"react"
:
"^17.0.2"
,
"react-dom"
:
"^17.0.2"
,
"react-router"
:
"^5.2.1"
,
...
...
projectSecondPart/src/model-data/PhotoApp.js
View file @
fe8d33e0
...
...
@@ -258,4 +258,4 @@ class PROG2053Models {
PROG2053Models
.
populatePhotoComments
();
export
default
PROG2053Models
;
module
.
exports
=
PROG2053Models
;
projectSecondPart/webServer.js
View file @
fe8d33e0
...
...
@@ -11,11 +11,11 @@
const
express
=
require
(
'
express
'
);
const
portno
=
300
0
;
// Port number to use
const
portno
=
300
1
;
// Port number to use
const
app
=
express
();
const
cs142models
=
require
(
'
./model
D
ata/
p
hotoApp.js
'
).
cs142models
;
const
PROG2053
=
require
(
'
./
src/
model
-d
ata/
P
hotoApp.js
'
).
PROG2053
;
// We have the express static module (http://expressjs.com/en/starter/static-files.html) do all
// the work for us.
...
...
@@ -35,7 +35,7 @@ app.get('/test/:p1', function (request, response) {
return
;
}
const
info
=
cs142
models
.
schemaInfo
();
const
info
=
PROG2053
models
.
schemaInfo
();
// Query didn't return an error but didn't find the SchemaInfo object - This
// is also an internal error return.
...
...
@@ -50,7 +50,7 @@ app.get('/test/:p1', function (request, response) {
* URL /user/list - Return all the User object.
*/
app
.
get
(
'
/user/list
'
,
function
(
request
,
response
)
{
response
.
status
(
200
).
send
(
cs142
models
.
userListModel
());
response
.
status
(
200
).
send
(
PROG2053
models
.
userListModel
());
return
;
});
...
...
@@ -60,7 +60,7 @@ app.get('/user/list', function (request, response) {
*/
app
.
get
(
'
/user/:id
'
,
function
(
request
,
response
)
{
const
id
=
request
.
params
.
id
;
const
user
=
cs142
models
.
userModel
(
id
);
const
user
=
PROG2053
models
.
userModel
(
id
);
if
(
user
===
null
)
{
console
.
log
(
`User with _id:
${
id
}
not found.`
);
response
.
status
(
400
).
send
(
'
Not found
'
);
...
...
@@ -75,7 +75,7 @@ app.get('/user/:id', function (request, response) {
*/
app
.
get
(
'
/photosOfUser/:id
'
,
function
(
request
,
response
)
{
const
id
=
request
.
params
.
id
;
const
photos
=
cs142
models
.
photoOfUserModel
(
id
);
const
photos
=
PROG2053
models
.
photoOfUserModel
(
id
);
if
(
photos
.
length
===
0
)
{
console
.
log
(
`Photos for user with _id:
${
id
}
not found.`
);
response
.
status
(
400
).
send
(
'
Not found
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment