Commit fe8d33e0 authored by Martin Wighus Holtmon's avatar Martin Wighus Holtmon
Browse files

projectSecondPart/Problem2 - Setup express server

parent 90b98584
This diff is collapsed.
......@@ -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",
......
......@@ -258,4 +258,4 @@ class PROG2053Models {
PROG2053Models.populatePhotoComments();
export default PROG2053Models;
module.exports = PROG2053Models;
......@@ -11,11 +11,11 @@
const express = require('express');
const portno = 3000; // Port number to use
const portno = 3001; // Port number to use
const app = express();
const cs142models = require('./modelData/photoApp.js').cs142models;
const PROG2053 = require('./src/model-data/PhotoApp.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 = cs142models.schemaInfo();
const info = PROG2053models.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(cs142models.userListModel());
response.status(200).send(PROG2053models.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 = cs142models.userModel(id);
const user = PROG2053models.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 = cs142models.photoOfUserModel(id);
const photos = PROG2053models.photoOfUserModel(id);
if (photos.length === 0) {
console.log(`Photos for user with _id:${id} not found.`);
response.status(400).send('Not found');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment