├── sample.env ├── .gitignore ├── README.md ├── .gitpod.yml ├── package.json ├── index.js ├── public └── style.css └── views └── index.html /sample.env: -------------------------------------------------------------------------------- 1 | PORT= 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # URL Shortener Microservice 2 | 3 | This is the boilerplate code for the URL Shortener Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice. 4 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-node-lts 2 | 3 | ports: 4 | - port: 3000 5 | onOpen: open-preview 6 | visibility: public 7 | 8 | tasks: 9 | - init: npm install 10 | command: npm run start 11 | 12 | vscode: 13 | extensions: 14 | - https://github.com/freeCodeCamp/freecodecamp-dark-vscode-theme/releases/download/v1.0.0/freecodecamp-dark-vscode-theme-1.0.0.vsix 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shorturl", 3 | "version": "0.0.3", 4 | "description": "API project for freeCodeCamp", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "dependencies": { 10 | "body-parser": "^1.19.0", 11 | "cors": "^2.8.5", 12 | "dotenv": "^8.2.0", 13 | "express": "^4.17.1" 14 | }, 15 | "license": "MIT" 16 | } 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const express = require('express'); 3 | const cors = require('cors'); 4 | const app = express(); 5 | 6 | // Basic Configuration 7 | const port = process.env.PORT || 3000; 8 | 9 | app.use(cors()); 10 | 11 | app.use('/public', express.static(`${process.cwd()}/public`)); 12 | 13 | app.get('/', function(req, res) { 14 | res.sendFile(process.cwd() + '/views/index.html'); 15 | }); 16 | 17 | // Your first API endpoint 18 | app.get('/api/hello', function(req, res) { 19 | res.json({ greeting: 'hello API' }); 20 | }); 21 | 22 | app.listen(port, function() { 23 | console.log(`Listening on port ${port}`); 24 | }); 25 | -------------------------------------------------------------------------------- /public/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, sans-serif; 3 | font-size: 16px; 4 | color: #222; 5 | background-color: #fff; 6 | text-align: center; 7 | line-height: 1.4em; 8 | } 9 | 10 | main { 11 | padding: 0; 12 | margin-top: 40px; 13 | } 14 | 15 | h3 { 16 | margin-top: 30px; 17 | } 18 | 19 | 20 | 21 | .user-stories li { 22 | margin-bottom: 1em; 23 | } 24 | 25 | a { 26 | color: #2574a9; 27 | } 28 | 29 | form { 30 | margin: 10px auto; 31 | padding: 20px; 32 | max-width: 600px; 33 | } 34 | 35 | label { 36 | margin-right: 10px; 37 | } 38 | 39 | input { 40 | padding: 5px; 41 | } 42 | 43 | input[type='text'] { 44 | width: 220px; 45 | text-align: center; 46 | } 47 | -------------------------------------------------------------------------------- /views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | URL Shortener Microservice | freeCodeCamp.org 6 | 11 | 12 | 13 | 14 | 15 |

URL Shortener Microservice

16 |
17 |
18 |
19 |
20 | URL Shortener 21 | 22 | 23 | 24 |
25 |
26 |
27 |
28 | 31 | 32 | 33 | --------------------------------------------------------------------------------