Skip to content

Commit 668d442

Browse files
committed
add cookie
1 parent a6e0be0 commit 668d442

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Caddyfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ route / {
44
reverse_proxy localhost:4010
55
}
66

7+
route /postman/cookie {
8+
reverse_proxy localhost:4010
9+
}
10+
711
route /http-api/echo {
812
reverse_proxy localhost:4010
913
}

custom-server/src/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fastifySwagger from '@fastify/swagger';
44
import swaggerUI from '@fastify/swagger-ui';
55
import fastifyStatic from '@fastify/static';
66
import formbody from '@fastify/formbody';
7+
import fastifyCookie from '@fastify/cookie';
78

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

@@ -47,6 +48,9 @@ const setupDocs = async (app) => {
4748
};
4849
export default async (app, _options) => {
4950
await app.register(formbody);
51+
await app.register(fastifyCookie, {
52+
secret: 'my-secret',
53+
});
5054
setUpStaticAssets(app);
5155

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

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

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

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"private": true,
1414
"dependencies": {
15+
"@fastify/cookie": "^11.0.1",
1516
"@fastify/formbody": "^8.0.1",
1617
"@fastify/static": "^8.0.2",
1718
"@fastify/swagger": "^9.2.0",

0 commit comments

Comments
 (0)