generated from agiledev-students-fall2023/generic-project-repository
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from agiledev-students-fall2023/sprint/2/spik…
…e/132/setup-backend setup and configured backend
- Loading branch information
Showing
11 changed files
with
7,213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.