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 @@ ...@@ -27,7 +27,7 @@
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"proxy": "http://localhost:4000", "proxy": "http://it2810-54.idi.ntnu.no:4000",
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"react-app", "react-app",
......
export function queryFetch(query: String) { export function queryFetch(query: String) {
return fetch('/graphql', { return fetch('http://it2810-54.idi.ntnu.no:4000/graphql', {
method: 'POST', method: 'POST',
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
"web-vitals": "^1.1.2" "web-vitals": "^1.1.2"
}, },
"scripts": { "scripts": {
"start": "nodemon src/server.ts --exec ts-node", "start": "nohup node src/server.js &",
"build": "tsc src/server.ts", "build": "tsc src/server.ts",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
......
...@@ -4,6 +4,7 @@ var { graphqlHTTP } = require('express-graphql'); ...@@ -4,6 +4,7 @@ var { graphqlHTTP } = require('express-graphql');
var { GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLList, GraphQLBoolean } = require('graphql'); var { GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLList, GraphQLBoolean } = require('graphql');
import {connect} from "./database" import {connect} from "./database"
import * as cors from 'cors';
const MovieType = new GraphQLObjectType({ const MovieType = new GraphQLObjectType({
name: "Movie", name: "Movie",
...@@ -106,7 +107,7 @@ function getSearchQuery(title: string, genre: string, order: boolean): string { ...@@ -106,7 +107,7 @@ function getSearchQuery(title: string, genre: string, order: boolean): string {
query = query + ' genre LIKE "%' + genre + '%"' query = query + ' genre LIKE "%' + genre + '%"'
} }
if (order) { if (order) {
query = query + ' ORDER BY year DESC' query = query + ' ORDER BY "year" DESC'
} }
console.log(query) console.log(query)
return query return query
...@@ -182,10 +183,35 @@ const Mutation = new GraphQLObjectType({ ...@@ -182,10 +183,35 @@ const Mutation = new GraphQLObjectType({
const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation}) const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation})
var app = express(); 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({ app.use('/graphql', graphqlHTTP({
schema: schema, schema: schema,
graphiql: true, graphiql: true,
})); }));
app.listen(4000, () => console.log('Now browse to localhost:4000/graphql on local')); app.listen(4000, () => console.log('Server running on port 4000'));
\ No newline at end of file
...@@ -4,7 +4,6 @@ var { graphqlHTTP } = require('express-graphql'); ...@@ -4,7 +4,6 @@ var { graphqlHTTP } = require('express-graphql');
var { GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLList, GraphQLBoolean } = require('graphql'); var { GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLList, GraphQLBoolean } = require('graphql');
import {connect} from "./database" import {connect} from "./database"
import * as cors from 'cors';
const MovieType = new GraphQLObjectType({ const MovieType = new GraphQLObjectType({
name: "Movie", name: "Movie",
...@@ -107,7 +106,7 @@ function getSearchQuery(title: string, genre: string, order: boolean): string { ...@@ -107,7 +106,7 @@ function getSearchQuery(title: string, genre: string, order: boolean): string {
query = query + ' genre LIKE "%' + genre + '%"' query = query + ' genre LIKE "%' + genre + '%"'
} }
if (order) { if (order) {
query = query + ' ORDER BY "year" DESC' query = query + ' ORDER BY year DESC'
} }
console.log(query) console.log(query)
return query return query
...@@ -183,35 +182,10 @@ const Mutation = new GraphQLObjectType({ ...@@ -183,35 +182,10 @@ const Mutation = new GraphQLObjectType({
const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation}) const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation})
var app = express(); 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({ app.use('/graphql', graphqlHTTP({
schema: schema, schema: schema,
graphiql: true, 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