Skip to content

Commit

Permalink
Merge pull request #123 from Arquisoft/development-angela
Browse files Browse the repository at this point in the history
Development angela
  • Loading branch information
angeeroza authored Apr 15, 2024
2 parents a767826 + cac58dd commit 64a82d8
Show file tree
Hide file tree
Showing 37 changed files with 17,106 additions and 30 deletions.
20 changes: 20 additions & 0 deletions apis/allquestionservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20

# Set the working directory in the container
WORKDIR /usr/src/apis/allquestionservice

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install app dependencies
RUN npm install

# Copy the app source code to the working directory
COPY . .

# Expose the port the app runs on
EXPOSE 8007

# Define the command to run your app
CMD ["node", "allquestions-api.js"]
58 changes: 58 additions & 0 deletions apis/allquestionservice/allquestions-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const express = require('express');
const mongoose = require('mongoose');
const Question = require('./question-model')
const bodyParser = require('body-parser');

const app = express();
const port = 8007;

const originEndpoint = process.env.REACT_APP_API_ORIGIN_ENDPOINT || 'http://localhost:3000';

const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
mongoose.connect(mongoUri);

// Middleware to parse JSON in request body
app.use(bodyParser.json());

app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', originEndpoint);
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});


app.get('/getAllQuestions', async (req, res) => {
try{

var questions = await Question.find({ });

var questionsList = [];

questions.forEach(q => {
questionsList.push({
enunciado: q.enunciado,
respuesta_correcta: q.respuesta_correcta
});
});

// Devolver la lista completa de usuarios
res.json(questionsList);


} catch (error) {
console.error('No hay preguntas:', error);
res.status(500).json({ message: 'Error interno del servidor' });
}
});

const server = app.listen(port, () => {
console.log(`Creation Service listening at http://localhost:${port}`);
});

server.on('close', () => {
mongoose.connection.close();
});

module.exports = server;
Binary file added apis/allquestionservice/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 64a82d8

Please sign in to comment.