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
Last active
June 21, 2022 20:28
-
-
Save blangue/c1ba8e1d2d590ec9163a4bc7b5cdb2b5 to your computer and use it in GitHub Desktop.
HeaderParser microservice
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
// index.js | |
// where your node app starts | |
// init project | |
require('dotenv').config(); | |
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/whoami", function (req, res) { | |
res.json({ipaddress: req.ip, language: req.header('accept-language'), software: req.header('user-agent')}); | |
}); | |
// listen for requests :) | |
var listener = app.listen(process.env.PORT || 3000, function () { | |
console.log('Your app is listening on port ' + listener.address().port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment