Add Header Parser Certification Project
This commit is contained in:
parent
5191dbf2a1
commit
82bbfefc5e
10 changed files with 1210 additions and 0 deletions
2
6-backend-dev/2-header-parser/.gitattributes
vendored
Normal file
2
6-backend-dev/2-header-parser/.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Tell Linguist to exclude HTML files to help Replit language detection.
|
||||||
|
*.html linguist-vendored
|
1
6-backend-dev/2-header-parser/.gitignore
vendored
Normal file
1
6-backend-dev/2-header-parser/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
1
6-backend-dev/2-header-parser/.prettierignore
Normal file
1
6-backend-dev/2-header-parser/.prettierignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.replit
|
10
6-backend-dev/2-header-parser/.replit
Normal file
10
6-backend-dev/2-header-parser/.replit
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
run = "npm start"
|
||||||
|
entrypoint = "index.js"
|
||||||
|
|
||||||
|
[packager]
|
||||||
|
language = "nodejs"
|
||||||
|
|
||||||
|
[packager.features]
|
||||||
|
packageSearch = true
|
||||||
|
guessImports = true
|
||||||
|
enabledForHosting = false
|
3
6-backend-dev/2-header-parser/README.md
Normal file
3
6-backend-dev/2-header-parser/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Request Header Parser Microservice
|
||||||
|
|
||||||
|
This is the boilerplate for the Request Header Parser Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/apis-and-microservices/apis-and-microservices-projects/request-header-parser-microservice
|
31
6-backend-dev/2-header-parser/index.js
Normal file
31
6-backend-dev/2-header-parser/index.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// index.js
|
||||||
|
// where your node app starts
|
||||||
|
|
||||||
|
// init project
|
||||||
|
require('dotenv').config();
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
|
||||||
|
// so that your API is remotely testable by FCC
|
||||||
|
const cors = require('cors');
|
||||||
|
app.use(cors({ optionsSuccessStatus: 200 })); // some legacy browsers choke on 204
|
||||||
|
|
||||||
|
// http://expressjs.com/en/starter/static-files.html
|
||||||
|
app.use(express.static('public'));
|
||||||
|
|
||||||
|
// http://expressjs.com/en/starter/basic-routing.html
|
||||||
|
app.get('/', function (req, res) {
|
||||||
|
res.sendFile(__dirname + '/views/index.html');
|
||||||
|
});
|
||||||
|
|
||||||
|
// your first API endpoint...
|
||||||
|
app.get('/api/whoami', function (req, res) {
|
||||||
|
res.json({ ipaddress: req.ip, language: req.headers["accept-language"], software: req.headers["user-agent"] });
|
||||||
|
console.log(req.headers)
|
||||||
|
});
|
||||||
|
|
||||||
|
// listen for requests :)
|
||||||
|
const listener = app.listen(process.env.PORT || 3000, function () {
|
||||||
|
console.log('Your app is listening on port ' + listener.address().port);
|
||||||
|
});
|
1067
6-backend-dev/2-header-parser/package-lock.json
generated
Normal file
1067
6-backend-dev/2-header-parser/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
29
6-backend-dev/2-header-parser/package.json
Normal file
29
6-backend-dev/2-header-parser/package.json
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "request-header-parser-microservice",
|
||||||
|
"version": "0.0.2",
|
||||||
|
"description": "API project for freeCodeCamp",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.1",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
|
"express": "^4.18.1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/freeCodeCamp/boilerplate-project-headerparser.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/freeCodeCamp/boilerplate-project-headerparser#readme",
|
||||||
|
"author": "freeCodeCamp <team@freecodecamp.org>",
|
||||||
|
"keywords": [
|
||||||
|
"freeCodeCamp",
|
||||||
|
"node",
|
||||||
|
"express"
|
||||||
|
],
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
32
6-backend-dev/2-header-parser/public/style.css
Normal file
32
6-backend-dev/2-header-parser/public/style.css
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
body {
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #222;
|
||||||
|
background-color: #FaFaFa;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 1.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
padding: 0;
|
||||||
|
margin-top: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
margin-top: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: monospace;
|
||||||
|
padding: 2px;
|
||||||
|
color: black;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #2574A9;
|
||||||
|
}
|
34
6-backend-dev/2-header-parser/views/index.html
vendored
Normal file
34
6-backend-dev/2-header-parser/views/index.html
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Request Header Parser</title>
|
||||||
|
<link rel="shortcut icon" href="https://cdn.hyperdev.com/us-east-1%3A52a203ff-088b-420f-81be-45bf559d01b1%2Ffavicon.ico" type="image/x-icon"/>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
|
||||||
|
<link href="style.css" rel="stylesheet" type="text/css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Request Header Parser Microservice</h2>
|
||||||
|
|
||||||
|
<h3>Example Usage:</h3>
|
||||||
|
<p>
|
||||||
|
<a href="api/whoami">[base url]/api/whoami</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Example Output:</h3>
|
||||||
|
<p>
|
||||||
|
<code>{"ipaddress":"::ffff:159.20.14.100","language":"en-US,en;q=0.5",<br>"software":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0"}</code>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="footer">
|
||||||
|
<p>
|
||||||
|
by <a href="https://github.com/CherryKitten">CherryKitten</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
Reference in a new issue