Skip to content

Commit

Permalink
Merge pull request #5 from elite-grub/refactor
Browse files Browse the repository at this point in the history
Refactor map component for docker and aws
  • Loading branch information
YesImKenny authored Mar 11, 2019
2 parents 30159e1 + 5c5b677 commit 6322d51
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
node_modules
server/database/config.js
docker-compose.yml
# Elastic Beanstalk Files
.elasticbeanstalk
!.elasticbeanstalk/*.config.yml
!.elasticbeanstalk/*.global.yml
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

FROM node:10.15-alpine

RUN mkdir -p /src/app

WORKDIR /src/app

COPY . /src/app

RUN npm install

EXPOSE 3333

CMD [ "npm", "run", "start" ]
15 changes: 15 additions & 0 deletions Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"AWSEBDockerrunVersion": "1",
"Ports": [
{
"HostPort": "3333",
"ContainerPort": "3333"
}
],
"Volumes": [
{
"HostDirectory": "/var/app",
"ContainerDirectory": "/var/app/"
}
]
}
Binary file modified client/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion client/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MapBox from './MapBox';
import MapText from './MapText';
import MapModal from './MapModal';
import { Border, Font } from './style.js';
import { config } from '../../server/database/config.js';

class App extends React.Component {
constructor(props) {
Expand All @@ -24,7 +25,7 @@ class App extends React.Component {
}

getRestaurant() {
axios.get(`http://localhost:3333/restaurant/${this.props.id}`)
axios.get(`${config.localhost}/restaurant/${this.props.id}`)
.then((res) => {
const restaurant = res.data[0];
console.log('got data to CLient!!', restaurant);
Expand Down
38 changes: 19 additions & 19 deletions client/dist/bundle.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions client/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
</head>
<body>
<div id="mapView"></div>
<!-- <script type="text/javascript" src="bundle.js"></script> -->
<script src="http://localhost:3333/bundle.js"></script>
<script type="text/javascript" src="bundle.js"></script>
<script>
const id = Math.floor(Math.random() * 100) + 1;
ReactDOM.render(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test:watch": "jest --watch",
"test:coverage": "jest --coverage --colors",
"build": "webpack --mode production --watch",
"start": "nodemon server/server.js",
"start": "node server/server.js",
"newstart": "node server/server.js && node seed.js",
"seed": "node seed.js"
},
"repository": {
Expand Down
113 changes: 58 additions & 55 deletions seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,64 @@ const Sequelize = require('sequelize');
const faker = require('faker');
const { config } = require('./server/database/config.js');

module.exports.seed = () => {
const sequelize = new Sequelize({
database: config.database,
username: config.username,
password: config.password,
dialect: config.dialect,
host: config.host,
});

const sequelize = new Sequelize({
database: 'elitemap',
username: config.username,
password: config.password,
dialect: 'postgres',
});

sequelize.authenticate().then(() => {
console.log('Connection Successful!');
}).catch((err) => {
console.error('No connection to database!', err);
})
.then(() => {
const Restaurants = sequelize.define('restaurants', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
street: {
type: Sequelize.STRING,
allowNull: false,
},
cityStateZip: {
type: Sequelize.STRING,
allowNull: false,
sequelize.authenticate().then(() => {
console.log('Connection Successful AT seed.js!');
}).catch((err) => {
console.error('No connection to database!', err);
})
.then(() => {
const Restaurants = sequelize.define('restaurants', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
street: {
type: Sequelize.STRING,
allowNull: false,
},
cityStateZip: {
type: Sequelize.STRING,
allowNull: false,
},
phone: {
type: Sequelize.STRING,
allowNull: false,
},
website: {
type: Sequelize.STRING,
allowNull: false,
},
},
phone: {
type: Sequelize.STRING,
allowNull: false,
},
website: {
type: Sequelize.STRING,
allowNull: false,
},
},
{ timestamps: false },
{ freezeTable: true });
Restaurants.sync({ force: true })
.then(() => {
for (let i = 0; i < 100; i += 1) {
Restaurants.create({
name: faker.lorem.words(),
street: faker.address.streetAddress(),
cityStateZip: `${faker.address.city()}, ${faker.address.stateAbbr()} ${faker.address.zipCode()}`,
phone: faker.phone.phoneNumberFormat(),
website: faker.internet.url(),
});
}
})
.catch(err => console.log(err));
});
{ timestamps: false },
{ freezeTable: true });
Restaurants.sync({ force: true })
.then(() => {
for (let i = 0; i < 100; i += 1) {
Restaurants.create({
name: faker.lorem.words(),
street: faker.address.streetAddress(),
cityStateZip: `${faker.address.city()}, ${faker.address.stateAbbr()} ${faker.address.zipCode()}`,
phone: faker.phone.phoneNumberFormat(),
website: faker.internet.url(),
});
}
})
.catch(err => console.log(err));
});
};
14 changes: 10 additions & 4 deletions server/database/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
const Sequelize = require('sequelize');
const { config } = require('./config.js');
const { seed } = require('../../seed.js');

const sequelize = new Sequelize({
database: 'elitemap',
database: config.database,
username: config.username,
password: config.password,
dialect: 'postgres',
dialect: config.dialect,
host: config.host,
});

sequelize.authenticate().then(() => {
console.log('Connection Successful!');
console.log('Connection Successful at index.js!');
}).catch((err) => {
console.error('No connection to database!', err);
});


const selectRestaurant = (async (id) => {
try {
seed();
} catch (err) {
return err;
}
try {
const res = await sequelize.query(`SELECT * FROM restaurants WHERE id = ${id}`);
return res[0];
Expand Down
5 changes: 2 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const express = require('express');
const bodyParser = require('body-parser');

const { selectRestaurant } = require('./database/index.js');

const app = express();
Expand All @@ -9,8 +8,8 @@ const port = 3333;
app.use(bodyParser.json());
app.use(express.static('./client/dist'));
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});

Expand Down

0 comments on commit 6322d51

Please sign in to comment.