Skip to content

Commit

Permalink
Updated Dockerfile to run with prod and cors
Browse files Browse the repository at this point in the history
  • Loading branch information
uo282892 committed May 4, 2023
1 parent 852fca1 commit 13df532
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion restapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ COPY . /app
WORKDIR /app
#Install the dependencies
RUN npm install
CMD [ "npm", "start" ]
CMD [ "npm", "run", "prod" ]
#CMD [ "npm", "start" ]
2 changes: 1 addition & 1 deletion restapi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ api.use(
credentials: true,
origin: ["https://20.168.251.141", "https://lomapen3a.cloudns.ph", "https://localhost",
"https://20.168.251.141:443", "https://lomapen3a.cloudns.ph:443", "https://localhost:443"],
allowedHeaders: ["Content-Type", "Authorization", "Access-Control-Allow-Origin"],
allowedHeaders: ["Content-Type", "Authorization"],
preflightContinue: true,
})
);
Expand Down
3 changes: 1 addition & 2 deletions restapi/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mongoose.connect(uri, options).then(
const metricsMiddleware:RequestHandler = promBundle({includeMethod: true});
app.use(metricsMiddleware);

app.use(cors());
app.use(bp.json());

app.use("/api", api)
Expand All @@ -35,7 +34,7 @@ try {
if (req.secure) {
return next();
}
res.redirect('https://'+req.hostname + req.url);
res.redirect('https://'+ "lomapen3a.cloudns.ph" + ":" + portHttps + req.url);
});

createServer(credentials, app)
Expand Down
5 changes: 5 additions & 0 deletions restapi/src/controllers/places/PlacesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {validationResult} from "express-validator";

const getPlaces = async (req: Request, res: Response): Promise<Response> => {
try {
res.header('Access-Control-Allow-Origin', '*');
const places: Array<PlaceType> = await Promise.resolve(Place.find());
return res.status(200).send(places);
}
Expand All @@ -15,6 +16,7 @@ const getPlaces = async (req: Request, res: Response): Promise<Response> => {

const addPlace = async (req: Request, res: Response): Promise<Response> => {
try {
res.header('Access-Control-Allow-Origin', '*');
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({errors: errors.array()})
Expand All @@ -34,6 +36,7 @@ const addPlace = async (req: Request, res: Response): Promise<Response> => {

const deletePlace = async (req: Request, res: Response): Promise<Response> => {
try {
res.header('Access-Control-Allow-Origin', '*');
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({errors: errors.array()})
Expand All @@ -50,6 +53,7 @@ const deletePlace = async (req: Request, res: Response): Promise<Response> => {

const updatePlace = async (req: Request, res: Response): Promise<Response> => {
try {
res.header('Access-Control-Allow-Origin', '*');
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({errors: errors.array()})
Expand All @@ -71,6 +75,7 @@ const updatePlace = async (req: Request, res: Response): Promise<Response> => {

const findPlaceByTitle = async (req: Request, res: Response): Promise<Response> => {
try {
res.header('Access-Control-Allow-Origin', '*');
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({errors: errors.array()})
Expand Down

0 comments on commit 13df532

Please sign in to comment.