Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .babelrc

This file was deleted.

2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules/
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"plugin:react/recommended",
"airbnb"
],
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
}
}
9 changes: 0 additions & 9 deletions .prettierrc

This file was deleted.

26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production


# Bundle app source
COPY . .

# build with webpack
ARG ENV=development
ENV ENV=${ENV}
RUN npx webpack build --config ./webpack.config.js --mode ${ENV} --env ENV=${ENV}


EXPOSE 3000
CMD [ "node", "server/server.js" ]
37 changes: 37 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = function (api) {
const env = api.env();
api.cache(false);
return {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: [
'last 2 versions',
],
},
corejs: '3',
useBuiltIns: 'usage',
},
],
[
'@babel/react',
{
plugins: [
'@babel/plugin-proposal-class-properties',
],
},
],
],
plugins: [
[
'babel-plugin-conditional-compile', {
define: {
ENV: env,
},
},
],
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class App extends Component {

handleLogin = () => {
let oldLink = window.location.pathname + window.location.search;
let link = window.location.origin.replace("http:", "https:") + "/api/signUpLogin";
if (link.includes("localhost:5000")) link = window.location.origin + "/api/signUpLogin";
let link = window.location.origin + "/api/signUpLogin";
if (ENV != "development") {
let link = link.replace("http:", "https:")
}
let encodedLink = encodeURIComponent(link);

this.props.cookies.set("redirectLink", oldLink, { path: "/" });
Expand Down
8 changes: 4 additions & 4 deletions client/src/index.js → client/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./components/App.js";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App.jsx';
// renders React Component "Root" into the DOM element with ID "root"
ReactDOM.render(
<App />,

document.getElementById("root")
document.getElementById('root'),
);

// allows for live updating
Expand Down
30 changes: 15 additions & 15 deletions client/src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,57 @@ function formatParams(params) {
// map it to a new array of URL string encoded key,value pairs
// join all the url params using an ampersand (&).
return Object.keys(params)
.map((key) => key + "=" + encodeURIComponent(params[key]))
.join("&");
.map((key) => `${key}=${encodeURIComponent(params[key])}`)
.join('&');
}

// convert a fetch result to a JSON object with error handling for fetch and json errors
function convertToJSON(res) {
if (!res.ok) {
throw `API request failed with response status ${res.status} and text: ${res.statusText}`;
throw Error(`API request failed with response status ${res.status} and text: ${res.statusText}`);
}

return res
.clone() // clone so that the original is still readable for debugging
.json() // start converting to JSON object
.catch((error) => {
.catch(() => {
// throw an error containing the text that couldn't be converted to JSON
return res.text().then((text) => {
throw `API request's result could not be converted to a JSON object: \n${text}`;
res.text().then((text) => {
throw Error(`API request's result could not be converted to a JSON object: \n${text}`);
});
});
}

// Helper code to make a get request. Default parameter of empty JSON Object for params.
// Returns a Promise to a JSON Object.
export function get(endpoint, params = {}, token = "") {
const fullPath = endpoint + "?" + formatParams(params);
export function get(endpoint, params = {}, token = '') {
const fullPath = `${endpoint}?${formatParams(params)}`;
return fetch(endpoint, {
method: "get",
method: 'get',
headers: {
"Content-type": "application/json",
token: token,
'Content-type': 'application/json',
token,
},
query: JSON.stringify(params),
})
.then(convertToJSON)
.catch((error) => {
// give a useful error message
throw `GET request to ${fullPath} failed with error:\n${error}`;
throw Error(`GET request to ${fullPath} failed with error:\n${error}`);
});
}

// Helper code to make a post request. Default parameter of empty JSON Object for params.
// Returns a Promise to a JSON Object.
export function post(endpoint, params = {}) {
return fetch(endpoint, {
method: "post",
headers: { "Content-type": "application/json" },
method: 'post',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify(params),
})
.then(convertToJSON) // convert result to JSON object
.catch((error) => {
// give a useful error message
throw `POST request to ${endpoint} failed with error:\n${error}`;
throw Error(`POST request to ${endpoint} failed with error:\n${error}`);
});
}
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.9"

services:
web-dev:
build:
context: .
args:
- ENV=development
ports:
- "3000:3000"
depends_on:
- mongo-dev
environment:
- FIREROAD_LINK=https://fireroad-dev.mit.edu/
- DATABASE_NAME=dev
- ATLAS_SRV=mongodb://root:example@mongo-dev:27017
mongo-dev:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
Loading