Add Timestamp microservice certification project
This commit is contained in:
parent
e27b5fcfd8
commit
5191dbf2a1
9 changed files with 1281 additions and 0 deletions
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"optOut": false,
|
||||
"lastUpdateCheck": 1660315504033
|
||||
}
|
1
6-backend-dev/1-timestamp/.gitignore
vendored
Normal file
1
6-backend-dev/1-timestamp/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules
|
1
6-backend-dev/1-timestamp/.upm/store.json
Normal file
1
6-backend-dev/1-timestamp/.upm/store.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":2,"languages":{"nodejs-npm":{"specfileHash":"841109fa8607713df4692d12c4ed6636","lockfileHash":"4efea01e9fd85355b9909a99a5f0d3c1","guessedImports":["express","cors"],"guessedImportsHash":"502789eefc6b035d6e7e94b19788d256"}}}
|
3
6-backend-dev/1-timestamp/README.md
Normal file
3
6-backend-dev/1-timestamp/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Timestamp Microservice
|
||||
|
||||
This is the boilerplate code for the Timestamp Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/apis-and-microservices/apis-and-microservices-projects/timestamp-microservice
|
63
6-backend-dev/1-timestamp/index.js
Normal file
63
6-backend-dev/1-timestamp/index.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
// index.js
|
||||
// where your node app starts
|
||||
|
||||
// init project
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
|
||||
// so that your API is remotely testable by FCC
|
||||
var 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", (req, res) => {
|
||||
const date = getDate("now");
|
||||
res.json({
|
||||
unix: Math.floor(date.getTime()),
|
||||
utc: date.toUTCString()
|
||||
});
|
||||
})
|
||||
|
||||
app.get("/api/:date", (req, res) => {
|
||||
console.log(req.params.date)
|
||||
const date = getDate(req.params.date)
|
||||
console.log(date)
|
||||
if (!isNaN(date.valueOf())) {
|
||||
res.json({
|
||||
unix: Math.floor(date.getTime()),
|
||||
utc: date.toUTCString(),
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
error: 'Invalid Date'
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const getDate = (date) => {
|
||||
if (date === "now") {
|
||||
date = new Date()
|
||||
} else if (/^\d+$/.test(date)) {
|
||||
date = new Date(parseInt(date))
|
||||
} else {
|
||||
date = new Date(date)
|
||||
}
|
||||
return date
|
||||
}
|
||||
|
||||
|
||||
// listen for requests :)
|
||||
var listener = app.listen(process.env.PORT, function () {
|
||||
console.log('Your app is listening on port ' + listener.address().port);
|
||||
});
|
1102
6-backend-dev/1-timestamp/package-lock.json
generated
Normal file
1102
6-backend-dev/1-timestamp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
29
6-backend-dev/1-timestamp/package.json
Normal file
29
6-backend-dev/1-timestamp/package.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "fcc-api-projects-boilerplate",
|
||||
"version": "0.0.1",
|
||||
"description": "An FCC Backend Challenge",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.0",
|
||||
"express": "^4.12.4",
|
||||
"qs": "^6.11.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/freeCodeCamp/boilerplate-project-timestamp.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
|
||||
},
|
||||
"homepage": "https://github.com/freeCodeCamp/boilerplate-project-timestamp#readme",
|
||||
"author": "freeCodeCamp <team@freecodecamp.org>",
|
||||
"keywords": [
|
||||
"node",
|
||||
"express",
|
||||
"freeCodeCamp"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
46
6-backend-dev/1-timestamp/public/style.css
Normal file
46
6-backend-dev/1-timestamp/public/style.css
Normal file
|
@ -0,0 +1,46 @@
|
|||
/****** Main Styling ******/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
hr {
|
||||
margin: 25px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: monospace;
|
||||
padding: 2px;
|
||||
color: black;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #2574A9;
|
||||
}
|
32
6-backend-dev/1-timestamp/views/index.html
Normal file
32
6-backend-dev/1-timestamp/views/index.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Timestamp Microservice | freeCodeCamp.org</title>
|
||||
<link rel="shortcut icon" href="https://cdn.freecodecamp.org/universal/favicons/favicon-32x32.png" 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>
|
||||
<h1>Timestamp Microservice</h1>
|
||||
<hr />
|
||||
<div class="container">
|
||||
<h3>Example Usage:</h3>
|
||||
<ul>
|
||||
<li><a href="api/2015-12-25">[project url]/api/2015-12-25</a></li>
|
||||
<li><a href="api/1451001600000">[project url]/api/1451001600000</a></li>
|
||||
</ul>
|
||||
|
||||
<h3>Example Output:</h3>
|
||||
<p>
|
||||
<code>{"unix":1451001600000, "utc":"Fri, 25 Dec 2015 00:00:00 GMT"}</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