const express = require('express');
const next = require('next');
const redirects = require("./redirects");
const cacheableResponse = require('cacheable-response');
const port = parseInt(process.env.PORT, 10) || 3001;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const KeyvRedis = require('@keyv/redis');
const Keyv = require('keyv');
const handle = app.getRequestHandler();
const keyvRedis = new KeyvRedis('redis://127.0.0.1:6399'); // TODO: Get from dotenv
const ssrCache = cacheableResponse({
ttl: 1000 * 60 * 120, // 2 hours
get: async ({ req, res, pagePath, queryParams }) => ({
data: await app.renderToHTML(req, res, pagePath, queryParams)
}),
cache: new Keyv({ store: keyvRedis }),
send: ({ data, res }) => res.send(data)
});
app.prepare().then(() => {
const server = express();
redirects.forEach(({ from, to, type = 301, method = 'get' }) => {
server[method](from, (req, res) => {
res.redirect(type, to)
})
});
server.use((req, res, next) => {
res.append('Set-Cookie', "HttpOnly;Secure;SameSite=Strict");
next();
});
server.get('/posts/:slug', (req, res) => {
const queryParams = { slug: req.params.slug };
const pagePath = '/post';
return ssrCache({
req,
res,
pagePath,
queryParams
});
});
server.get('/', (req, res) => {
const pagePath = '/';
return ssrCache({
req,
res,
pagePath
});
});
server.all('*', (req, res) => {
//console.dir(req.url);
return handle(req, res)
});
server.listen(port, err => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`)
})
});
<p id="p">Example: <i>italic</i> and <b>bold</b></p>
From <input id="start" type="number" value=1> – To <input id="end" type="number" value=4>
<button id="button">Click to select</button>
let range = new Range();
range.setStart(p, start.value);
range.setEnd(p, end.value);
// применим выделение, объясняется далее
document.getSelection().removeAllRanges();
document.getSelection().addRange(range);
const [data, setData] = useState(null);
useEffect(() => {
const controller = new AbortController()
fetchData(controller.signal).then(setData)
return () => controller.abort()
}, [fetchData, setData])
const data = useMemo(() => array.map(mapper).filter(predicate).reduce(reducer), [array])
const handler = useCallback(() => {
// что-то сделать
}, [])
useEffect(() => {
handler(value)
// если не использовать useCallback, эффект будет срабатывать постоянно
}, [handler, value])
mkdir /target
mount none -t tmpfs -o size=1G /target/
debootstrap stable /target/ https://deb.debian.org/debian/
echo "Killer_system" > /target/etc/debian_chroot
chroot /target
mount none -t proc /proc/
mount none -t sysfs /sys/
mount none -t devtmpfs /dev/
mount none -t devpts /dev/pts/
apt install openssh-server
echo "Port 11122" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
/etc/init.d/ssh start
passwd root
ssh root@<IP> -p 11122
echo 1 > /sys/block/sda/device/delete
for i in /sys/class/scsi_host/host?/scan ; do echo "- - -" > $i ; done
dd if=/dev/urandom of=/dev/sdb bs=4096
echo b > /proc/sysrq-trigger
import React from 'react';
import styled from 'styled-components';
const SVG = styled.svg`
display: inline-block;
vertical-align: middle;
`;
const Icon = ({ name, ...props }) {
if (!name) {
throw new Error('Unknown icon name!');
}
return (
<SVG {...props}>
<use xlinkHref={`#icon-${name}`} />
</SVG>
);
}
export default Icon;
import React from 'react';
import styled from 'styled-components';
import { Icon } from './components';
const StyledIcon = styled(Icon)`
fill: ${props => props.state.fill};
`;
const Example = ({ iconState }) => <StyledSVG name="profile" state={iconState} />;
export default Example;
app.get('/api/v1/bitcoin', function (req, res) {
//запрос coinmarketcap
.then(response => res.json(response))
.catch(() => res.send("Ops something went wrong"))
})
import io from "socket.io-client";
import { isAuthenticated} from "../Api/Auth"
const jwt = isAuthenticated().token
const socket = io.connect('http://localhost:4001',
{ query: {token: jwt}
})
export const testSoket = () => {
socket.on("news")
socket.on('disconnect', function(){});
}
`${process.execPath}/db.sqlite3`