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
- 176 LFX Mentorship
- 176 LFX Mentorship: Linux Kernel
- 750 Linux Foundation IT Professional Programs
- 373 Cloud Engineer IT Professional Program
- 169 Advanced Cloud Engineer IT Professional Program
- 74 DevOps IT Professional Program - Discontinued
- 4 DevOps & GitOps IT Professional Program
- 99 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 1 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 3 Cloud & Containers Training
- 1 Cybersecurity Training
- 1 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 1 Open Source Best Practice Training
- 1 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 950 Programming and Development
- 310 Kernel Development
- 622 Software Development
- 982 Software
- 374 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 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)
