Skip to content

Commit

Permalink
Merge pull request #141 from agiledev-students-fall2023/sprint/2/spik…
Browse files Browse the repository at this point in the history
…e/132/setup-backend

setup and configured backend
  • Loading branch information
hasiburratul authored Nov 2, 2023
2 parents da7e1ee + 2c126d8 commit 838d2ba
Show file tree
Hide file tree
Showing 11 changed files with 7,213 additions and 4 deletions.
6 changes: 6 additions & 0 deletions back-end/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FRONTEND_URL = 'http://localhost:3000'
FRONTEND_PORT = 3000

BACKEND_URL = 'http://localhost:5000'
BACKEND_PORT = 5000

56 changes: 56 additions & 0 deletions back-end/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: 'standard',
overrides: [
{
env: {
node: true
},
files: [
'.eslintrc.{js,cjs}'
],
parserOptions: {
sourceType: 'script'
}
}
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
rules: {
'semi': [
'error',
'always'
],
'no-var': [
'error',
],
'prefer-const': ['warn', {
'destructuring': 'any',
'ignoreReadBeforeAssign': false
}],
'curly': ['warn'],
'eqeqeq': ['error'],
'no-multi-spaces': ['warn'],
'no-lone-blocks': ['error'],
'no-self-compare': ['error'],
'no-unused-expressions': ['error'],
'no-useless-call': ['error'],
'no-use-before-define': ['warn'],

'camelcase': ['warn', { properties: 'never' }],
'func-call-spacing': ['off'],
'no-lonely-if': ['off'],
'array-bracket-spacing': ['warn'],

'no-console': ['off'],
"space-before-function-paren": ["off"],
"quotes": ["off"],
"indent": "off"
}
}
52 changes: 52 additions & 0 deletions back-end/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// IMPORTS
import express from "express"; // ESM import style!
import morgan from "morgan";
import cors from "cors";
import url from 'url';
import path from 'path';
// import multer from "multer"; - configure when required

const app = express(); // instantiate an Express object

// MIDDLEWARES

// enable CORS - to allow requests from React frontend to reach the Express backend
app.use(cors());

// Later during deployment:
// const corsOptions = {
// origin: 'http://localhost:3000', // allow only the React frontend to connect
// methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
// credentials: true, // allow session cookie from browser to pass through
// optionsSuccessStatus: 200,
// };
// app.use(cors(corsOptions));

// serve static files from the public folders
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
app.use(express.static(path.join(__dirname, 'public')));

// parse JSON in the request body
app.use(express.json());

// parse urlencoded data in the request body
app.use(express.urlencoded({ extended: true }));

// log HTTP requests
app.use(morgan("dev"));

// ROUTE HANDLERS

// testing function
app.get("/", (req, res) => {
res.send("Hello!");
});

// testing cross origin requests - login username and password
app.post("/api/student/login", (req, res) => {
console.log(req.body);
res.send("Hello!1");
});

// export the express app we created to make it available to other modules
export default app;
Loading

0 comments on commit 838d2ba

Please sign in to comment.