Skip to content

Commit

Permalink
unspecified
Browse files Browse the repository at this point in the history
  • Loading branch information
helagro committed Mar 17, 2024
1 parent e47afd2 commit 4e3691b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
const express = require('express')
const path = require('path')
const express = require("express")
const path = require("path")

const app = express()
const rootPath = process.env.ROOT_PATH || '/resume'
const folderPath = path.join(__dirname, 'docs')
const rootPath = process.env.ROOT_PATH || "/resume"
const folderPath = path.join(__dirname, "docs")
const port = process.env.PORT || 8080

app.use((req, res, next) => {
console.log(`Request received: ${req.method} ${req.url}`)
next()
console.log(`Request received: ${req.method} ${req.url}`)
next()
})

app.use(rootPath, express.static(path.join(__dirname, 'docs')))
app.use(rootPath, express.static(path.join(__dirname, "docs")))

app.get("/:filename", (req, res, next) => {
const filename = req.params.filename
const filePath = path.join(staticFilesDirectory, filename)

fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) return next()

res.sendFile(filePath)
})
})

app.listen(port, () => {
console.log(`Server is running on port ${port}, hosting ${folderPath}`)
console.log(`Server is running on port ${port}, hosting ${folderPath}`)
})

0 comments on commit 4e3691b

Please sign in to comment.