-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from fga-eps-mds/173_organizar_gateway
173 organizar gateway
- Loading branch information
Showing
3 changed files
with
34 additions
and
5 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,3 @@ | ||
services: | ||
- name: user | ||
url: http://localhost:8000 |
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
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 |
---|---|---|
@@ -1,16 +1,37 @@ | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
|
||
import express from 'express'; | ||
import cors from 'cors'; | ||
import logger from 'morgan'; | ||
import helmet from 'helmet'; | ||
import httProxy from 'express-http-proxy' | ||
import { resolve } from 'path' | ||
import { readFileSync } from 'fs' | ||
import { load } from 'js-yaml' | ||
const app = express(); | ||
|
||
const pathFile = resolve(process.cwd(), 'config.yml') | ||
const readConfig = readFileSync(pathFile, {encoding: 'utf8'}) | ||
const { services } = load(readConfig, {json: true}) | ||
|
||
app.use(express.json()); | ||
|
||
app.use(cors()); | ||
app.use(logger('start')) | ||
app.use(helmet()) | ||
app.use(express.urlencoded({extended: true})) | ||
|
||
app.get('/', (req, res) => { | ||
return res.json({ message: 'Running Gateway' }) | ||
}) | ||
|
||
services.forEach(({ name, url }) => { | ||
app.use(`/${name}`, httProxy(url, {timeout: 3000})) | ||
|
||
}); | ||
|
||
const PORT = process.env.PORT || 4000; | ||
|
||
const gateway = app.listen(PORT, () => { | ||
console.log(`Gateway is running on ${PORT}`); | ||
}); | ||
|
||
module.exports = { gateway, app }; | ||
export { gateway, app }; |