From b3c9f1919804351455c74e60a499444e18df7bd6 Mon Sep 17 00:00:00 2001 From: trymg <trymg@stud.ntnu.no> Date: Wed, 27 Oct 2021 16:08:35 +0200 Subject: [PATCH] merged new changes, deployment should work --- client/package.json | 2 +- client/src/components/services.ts | 2 +- server/package.json | 2 +- server/src/server.ts | 30 +++++++++++++++++-- .../src/{server_build.ts => server_local.ts} | 30 ++----------------- 5 files changed, 33 insertions(+), 33 deletions(-) rename server/src/{server_build.ts => server_local.ts} (90%) diff --git a/client/package.json b/client/package.json index 792c678..9538abf 100644 --- a/client/package.json +++ b/client/package.json @@ -27,7 +27,7 @@ "test": "react-scripts test", "eject": "react-scripts eject" }, - "proxy": "http://localhost:4000", + "proxy": "http://it2810-54.idi.ntnu.no:4000", "eslintConfig": { "extends": [ "react-app", diff --git a/client/src/components/services.ts b/client/src/components/services.ts index 76e9a0a..940a8c3 100644 --- a/client/src/components/services.ts +++ b/client/src/components/services.ts @@ -1,5 +1,5 @@ export function queryFetch(query: String) { - return fetch('/graphql', { + return fetch('http://it2810-54.idi.ntnu.no:4000/graphql', { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ diff --git a/server/package.json b/server/package.json index 0d98b02..97fb51c 100644 --- a/server/package.json +++ b/server/package.json @@ -27,7 +27,7 @@ "web-vitals": "^1.1.2" }, "scripts": { - "start": "nodemon src/server.ts --exec ts-node", + "start": "nohup node src/server.js &", "build": "tsc src/server.ts", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/server/src/server.ts b/server/src/server.ts index 319f68e..6b2072d 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -4,6 +4,7 @@ var { graphqlHTTP } = require('express-graphql'); var { GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLList, GraphQLBoolean } = require('graphql'); import {connect} from "./database" +import * as cors from 'cors'; const MovieType = new GraphQLObjectType({ name: "Movie", @@ -106,7 +107,7 @@ function getSearchQuery(title: string, genre: string, order: boolean): string { query = query + ' genre LIKE "%' + genre + '%"' } if (order) { - query = query + ' ORDER BY year DESC' + query = query + ' ORDER BY "year" DESC' } console.log(query) return query @@ -182,10 +183,35 @@ const Mutation = new GraphQLObjectType({ const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation}) + var app = express(); + +// Add headers +app.use(function (req, res, next) { + + // Website you wish to allow to connect + res.setHeader('Access-Control-Allow-Origin', '*'); + + // Request methods you wish to allow + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); + + // Request headers you wish to allow + res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); + + // Set to true if you need the website to include cookies in the requests sent + // to the API (e.g. in case you use sessions) + res.setHeader('Access-Control-Allow-Credentials', true); + + // Pass to next layer of middleware + next(); +}); + + +app.use(cors()); + app.use('/graphql', graphqlHTTP({ schema: schema, graphiql: true, })); -app.listen(4000, () => console.log('Now browse to localhost:4000/graphql on local')); \ No newline at end of file +app.listen(4000, () => console.log('Server running on port 4000')); diff --git a/server/src/server_build.ts b/server/src/server_local.ts similarity index 90% rename from server/src/server_build.ts rename to server/src/server_local.ts index 6b2072d..319f68e 100644 --- a/server/src/server_build.ts +++ b/server/src/server_local.ts @@ -4,7 +4,6 @@ var { graphqlHTTP } = require('express-graphql'); var { GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLList, GraphQLBoolean } = require('graphql'); import {connect} from "./database" -import * as cors from 'cors'; const MovieType = new GraphQLObjectType({ name: "Movie", @@ -107,7 +106,7 @@ function getSearchQuery(title: string, genre: string, order: boolean): string { query = query + ' genre LIKE "%' + genre + '%"' } if (order) { - query = query + ' ORDER BY "year" DESC' + query = query + ' ORDER BY year DESC' } console.log(query) return query @@ -183,35 +182,10 @@ const Mutation = new GraphQLObjectType({ const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation}) - var app = express(); - -// Add headers -app.use(function (req, res, next) { - - // Website you wish to allow to connect - res.setHeader('Access-Control-Allow-Origin', '*'); - - // Request methods you wish to allow - res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); - - // Request headers you wish to allow - res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); - - // Set to true if you need the website to include cookies in the requests sent - // to the API (e.g. in case you use sessions) - res.setHeader('Access-Control-Allow-Credentials', true); - - // Pass to next layer of middleware - next(); -}); - - -app.use(cors()); - app.use('/graphql', graphqlHTTP({ schema: schema, graphiql: true, })); -app.listen(4000, () => console.log('Server running on port 4000')); +app.listen(4000, () => console.log('Now browse to localhost:4000/graphql on local')); \ No newline at end of file -- GitLab