LFW212 : ch8-lab-1 - unable to validate
First of all, this chapter is only described with Fastify and I think that's a huge problem because we don't all use this framework.
I implemented the lab 1 with express but I can't validate

Any idea please ?
Comments
-
[Spoiler] The solution for express :
var express = require('express')
var router = express.Router()
var got = require('got')router.get('/', async function (req, res) {
const { url } = req.querytry {
new URL(url)
} catch {
return res.sendStatus(400)
}try {
const {
statusCode,
body,
headers
} = await got(url, { retry: 0 })res
.set(headers)
.status(statusCode)
.send(body)
} catch (e) {
res.sendStatus(e.response ? e.response.statusCode : 500)
}
})module.exports = router
0 -
@luxfero both the training and the exams are about core skills, not framework choice. The fact you implemented in Express instead is proof that you'll be capable within the exam environment.
0 -
Is it better to use library? The code will be shorter.
My solution for review:
routes/index.js
const express = require('express');
const requestProxy = require("express-request-proxy");
const router = express.Router();router.get('/', async function(req, res, next) {
const { url } = req.query
const proxy = requestProxy({ url });
proxy(req, res, next);
});module.exports = router;
app.js
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');var indexRouter = require('./routes/index');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));app.use('/', indexRouter);
app.use(function(req, res, next) {
next(createError(404));
});app.use(function(err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};res.status(err.status || 500);
res.render('error');
});module.exports = app;
0 -
@chesterheng you can use whatever you like, the exam is agnostic to give you freedom to choose. Your solution looks fine to me
0
Categories
- All Categories
- 179 LFX Mentorship
- 179 LFX Mentorship: Linux Kernel
- 778 Linux Foundation IT Professional Programs
- 384 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 76 DevOps IT Professional Program - Discontinued
- 8 DevOps & GitOps IT Professional Program
- 104 Cloud Native Developer IT Professional Program
- 7.7K Training Courses & Learning Paths
- 21 AI & ML Training
- 2 Blockchain & Decentralized Identity Training
- 54 Cloud & Containers Training
- 7 Cybersecurity Training
- 5 DevOps & Site-Reliability Training
- 3 Linux Kernel Development Training
- 3 Networking Training
- 2 Open Source Best Practice Training
- 12 System Administration Training
- 1 System Engineering Training
- 6 Web & Application Development Training
- 799 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 97 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 92 Storage
- 776 Linux Distributions
- 83 Debian
- 68 Fedora
- 25 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 32 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 474 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 104 Linux Security
- 79 Network Management
- 102 System Management
- 47 Web Management
- 194 Mobile Computing
- 32 Android
- 146 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 409 Off Topic
- 129 Introductions
- 36 Study Material
- 1.1K Programming and Development
- 312 Kernel Development
- 739 Software Development
- 1K Software
- 421 Applications
- 183 Command Line
- 5 Compiling/Installing
- 71 Games
- 320 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)
