forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from Arquisoft/development-angela
Development angela
- Loading branch information
Showing
37 changed files
with
17,106 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.