I hosted express server as google cloud function
when ever I hit following link it works perfectly
https://<cloud-function-link>/<project-id>/static/
but if I remove trailing slash / at the end https://<cloud-function-link>/<project-id>/static
it redirects to https://<cloud-function-link>/static
and give me 403 error
I want it to work with both trailing / and without it.
my app.yaml
runtime: nodejs12
handlers:
- url: /static
static_dir: public
- url: /.*
script: auto
my index.js
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
require("dotenv/config");
//routes
const authRoute = require("./routes/auth.js");
const adminRoute = require("./routes/admin.js");
//middleweres
//converting body into json using body parser
app.use(
cors({
origin: true,
credentials: true,
exposedHeaders: ["auth-token"],
})
);
app.use(cookieParser());
app.use(bodyParser.json());
app.use("/static", express.static("public"));
app.use("/api/auth", authRoute);
app.use("/api/admin", adminRoute);
// starting express server
if (process.env.BUILD === "dev")
app.listen(5000, () => {
console.log("listning on port 5000");
});
module.exports = {
app,
}
;
question from:
https://stackoverflow.com/questions/65952979/express-server-on-google-cloud-functions-can-not-serve-static-file-without-trail 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…