Skip to content

Commit

Permalink
add cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
dzencot committed Nov 11, 2024
1 parent a6e0be0 commit 668d442
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ route / {
reverse_proxy localhost:4010
}

route /postman/cookie {
reverse_proxy localhost:4010
}

route /http-api/echo {
reverse_proxy localhost:4010
}
Expand Down
14 changes: 14 additions & 0 deletions custom-server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fastifySwagger from '@fastify/swagger';
import swaggerUI from '@fastify/swagger-ui';
import fastifyStatic from '@fastify/static';
import formbody from '@fastify/formbody';
import fastifyCookie from '@fastify/cookie';

import appConfig from '../../app.config.json' with {type: 'json'}

Expand Down Expand Up @@ -47,6 +48,9 @@ const setupDocs = async (app) => {
};
export default async (app, _options) => {
await app.register(formbody);
await app.register(fastifyCookie, {
secret: 'my-secret',
});
setUpStaticAssets(app);

await setupDocs(app);
Expand Down Expand Up @@ -110,5 +114,15 @@ export default async (app, _options) => {

app.post('/http-api/echo', (req, res) => res.send(req.body));

app.get('/postman/cookie', (req, res) => {
res.setCookie('myCookie', 'cookieValue', {
path: '/',
httpOnly: true,
secure: true, // Используйте true, если вы работаете с HTTPS
maxAge: 3600 // Время жизни куки в секундах
})
.send('Done!');
});

return app;
};
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"private": true,
"dependencies": {
"@fastify/cookie": "^11.0.1",
"@fastify/formbody": "^8.0.1",
"@fastify/static": "^8.0.2",
"@fastify/swagger": "^9.2.0",
Expand Down

0 comments on commit 668d442

Please sign in to comment.