diff --git a/app.js b/app.js index 6d9c2684..9d36ab58 100644 --- a/app.js +++ b/app.js @@ -62,18 +62,25 @@ connect.then( } ); -app.use('/', indexRouter); + app.use("/", adminRouter); app.use("/", afterDeploymentRouter); -app.use( - "/graphql", - graphqlHTTP({ - schema: schema, - graphiql: true, - }) -); -const headerMiddleware = require("./middlewares/HeaderMiddleware"); -app.use(headerMiddleware); + +app.use((req, res, next) => { + res.setHeader("Access-Control-Allow-Origin", "*"); + res.setHeader( + "Access-Control-Allow-Methods", + "OPTIONS, GET, POST, PUT, PATCH, DELETE" + ); + res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"); + + if (req.method === "OPTIONS") { + return res.sendStatus(200); + } + next(); +}); + +app.use('/', indexRouter); app.use("/", listenerRouter); app.use("/", tokensListRouter); app.use("/", deploypairRouter); @@ -86,6 +93,14 @@ app.use("/", pathRouter); app.use("/", readWasmRouter); app.use("/", setUserForRemoveLiquidityCSPRRouter); +app.use( + "/graphql", + graphqlHTTP({ + schema: schema, + graphiql: true, + }) +); + // catch 404 and forward to error handler app.use(function (req, res, next) { next(createError(404)); diff --git a/middlewares/HeaderMiddleware.js b/middlewares/HeaderMiddleware.js deleted file mode 100644 index a9d5bad5..00000000 --- a/middlewares/HeaderMiddleware.js +++ /dev/null @@ -1,40 +0,0 @@ -module.exports = function (req, res, next) { - var allowedOrigins = [ - "https://casper-swap.herokuapp.com/", - "http://casper-swap.herokuapp.com/", - "https://main.d2nr1bes87n0gc.amplifyapp.com/", - "http://main.d2nr1bes87n0gc.amplifyapp.com/", - ]; - var origin = req.headers.origin; - - if (allowedOrigins.indexOf(origin) > -1) { - res.setHeader("Access-Control-Allow-Origin", origin); - console.log("host matched"); - - res.setHeader("Cache-Control", "no-cache"); - // res.setHeader("Access-Control-Allow-Origin", process.env.FRONTEND_URL); - res.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, DELETE"); - res.setHeader("Access-Control-Allow-Credentials", "true"); - res.setHeader("Access-Control-Expose-Header", "DAV, content-length, Allow"); - res.setHeader( - "Access-Control-Allow-Headers", - "Content-Type, Authorization, X-Requested-With, Cookies, Set-Cookie" - ); - - // console.log("req.method : " + req.method); - - // res.setHeader("Access-Control-Request-Headers", "*"); - if (req.method == "OPTIONS") { - return res.status(200).json({}); - } - - next(); - } else { - //res.setHeader("Access-Control-Allow-Origin", "*"); - console.log("host not matched"); - return res.status(400).json({ - success: false, - message: "host not matched!", - }); - } -};