Skip to content
Snippets Groups Projects
Commit b3c9f191 authored by Trym Grande's avatar Trym Grande
Browse files

merged new changes, deployment should work

parent 399263b3
No related branches found
No related tags found
No related merge requests found
......@@ -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",
......
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({
......
......@@ -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"
......
......@@ -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'));
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment