diff --git a/client/package.json b/client/package.json index 792c678e7d3149578fd7bbe5ecc2d604d7971718..9538abff421391f9885998497b11586f60618b20 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 76e9a0a188ab4a05cc6db2151425417ad9c7590d..940a8c30ae6fdc06ef7bb9868e8da050cf99ce74 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 0d98b02f3e549be5d8d9026691da6b910ea89148..97fb51c0351230378e7dee9c812a1e0225edf783 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 319f68e4574ef356938ddc62a1c6b5ff5f4c6ec2..6b2072d83d1cbb93acc3f9f9695922d2f8347417 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 6b2072d83d1cbb93acc3f9f9695922d2f8347417..319f68e4574ef356938ddc62a1c6b5ff5f4c6ec2 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