Allow changing of root subdirectory
So that the app can be deployed anywhere! Just change the
environment variable `CHIPCHOC_BASE_URL` and you're all set 😉
This commit is contained in:
parent
74ecea0af9
commit
393e9c2652
3 changed files with 12 additions and 3 deletions
|
@ -3,3 +3,4 @@ CHIPCHOC_EMAIL_PORT=587
|
|||
CHIPCHOC_EMAIL_SECURE=false
|
||||
CHIPCHOC_EMAIL_USER=user@example.com
|
||||
CHIPCHOC_EMAIL_PASSWORD=badexample
|
||||
CHIPCHOC_BASE_URL=/
|
||||
|
|
|
@ -23,6 +23,7 @@ CHIPCHOC_EMAIL_PORT=587
|
|||
CHIPCHOC_EMAIL_SECURE=false
|
||||
CHIPCHOC_EMAIL_USER=user@example.com
|
||||
CHIPCHOC_EMAIL_PASSWORD=badexample
|
||||
CHIPCHOC_BASE_URL=/
|
||||
```
|
||||
|
||||
...then start [Rollup](https://rollupjs.org):
|
||||
|
|
13
server.js
13
server.js
|
@ -3,6 +3,7 @@ const nodemailer = require('nodemailer')
|
|||
|
||||
require('dotenv').config()
|
||||
|
||||
// handle debug mode
|
||||
let DEBUG
|
||||
|
||||
if (process.env.DEBUG || process.env.CHIPCHOC_DEBUG) {
|
||||
|
@ -25,9 +26,15 @@ const perumal = nodemailer.createTransport({
|
|||
},
|
||||
})
|
||||
|
||||
// decide base url for app (can be configured)
|
||||
let baseUrl = process.env.CHIPCHOC_BASE_URL || '/'
|
||||
|
||||
const app = express()
|
||||
var expressWs = require('express-ws')(app)
|
||||
|
||||
const router = express.Router()
|
||||
app.use(baseUrl, router)
|
||||
|
||||
const port = process.env.CHIPCHOC_PORT || 5000
|
||||
|
||||
const cors = require('cors')
|
||||
|
@ -35,7 +42,7 @@ const path = require('path')
|
|||
|
||||
app.use(cors())
|
||||
|
||||
app.get('/air', (req, res) => {
|
||||
router.get('/air', (req, res) => {
|
||||
console.log(`Searching for contacts with the term: ${req.query.name}`)
|
||||
res.send({
|
||||
success: true,
|
||||
|
@ -44,7 +51,7 @@ app.get('/air', (req, res) => {
|
|||
})
|
||||
|
||||
|
||||
app.ws('/hit-send', (ws, request) => {
|
||||
router.ws('/hit-send', (ws, request) => {
|
||||
console.log('Hitting send on some emails!')
|
||||
|
||||
ws.on('message', async (message) => {
|
||||
|
@ -92,7 +99,7 @@ app.ws('/hit-send', (ws, request) => {
|
|||
})
|
||||
|
||||
app.use(express.static('public'))
|
||||
app.get('/', (req, res) => {
|
||||
router.get('/', (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname, 'public', 'index.html'))
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue