Skip to content

Commit

Permalink
changed bodyparser limit
Browse files Browse the repository at this point in the history
fixed issue with geocoder while trying to host a listing
  • Loading branch information
jalajcodes committed Sep 15, 2020
1 parent f46db3c commit 8100f2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/graphql/resolvers/Listing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ export const ListingResolvers: IResolvers = {
if (!viewer) {
throw new Error(`You must be logged in to create a new Listing.`);
}

// remove the street info from the recived address (because api doesn't work with streets)
const addrArray = input.address.split(',');
addrArray.shift();
const tempAdr = addrArray.join(',');
// get the country admin and city from the geocoder
const { admin, city, country } = await geocode(input.address);
const { admin, city, country } = await geocode(tempAdr);

if (!country || !admin || !city) {
throw new Error(`Invalid Address Input`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dotenv.config();

import express, { Application } from 'express';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import { ApolloServer } from 'apollo-server-express';
import { typeDefs, resolvers } from './graphql/index';
import { connectDatabase } from './database';
Expand All @@ -13,7 +14,7 @@ const mount = async (app: Application) => {
// Connect to database
const db = await connectDatabase();

// Use Cookie Parser Middleware
app.use(bodyParser.json({ limit: '2mb' }));
app.use(cookieParser(process.env.COOKIE_SECRET));

// Instantiate apollo server instance
Expand Down

0 comments on commit 8100f2b

Please sign in to comment.