Answer the question
In order to leave comments, you need to log in
How to reach the service on the docker?
I wrote a simple service on the node and launched it using docker (as in the instructions), everything seems to work, but when I went into the postman, I couldn’t get through to the service. How to make a request to such servers?
I get the following result:
Did I do everything right and what path should I enter in postman? Thanks in advance
dockerfile
FROM node:8
WORKDIR /srv
ADD . .
RUN npm install
EXPOSE 3000
CMD ["node", "server.js"]
{
"ListenerArn": "placeholder",
"Conditions": [
{
"Field": "path-pattern",
"Values": [
"/api/tasks*"
]
}
],
"Priority": 3,
"Actions": [
{
"Type": "forward",
"TargetGroupArn": "placeholder"
}
]
}
const Koa = require('koa');
const Router = require('koa-router');
const db = require('./db.json');
const app = new Koa();
const router = new Router();
// logger
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get('X-Response-Time');
console.log(`${ctx.method} ${ctx.url} - ${rt}`);
});
// x-response-time
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
router.get('/api/tasks/by-forester/:foresterId', async (ctx, next) => {
const id = parseInt(this.params.foresterId);
ctx.body = db.posts.filter((task) => task.forester == id);
await next();
});
router.get('/api/tasks/by-supervisor/:supervisorId', async (ctx, next) => {
const id = parseInt(this.params.supervisorId);
ctx.body = db.posts.filter((task) => task.supervisor == id);
await next();
});
router.get('/api/', async (ctx, next) => {
ctx.body = "API ready to receive requests";
await next();
});
router.get('/', async (ctx, next) => {
ctx.body = "Ready to receive requests";
await next();
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000, () => {
console.log("Server work on port 3000");
});
Answer the question
In order to leave comments, you need to log in
Recreate container with -p 3000:3000
. EXPOSE by itself does not forward ports.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question