bmullan91 / express-subdomain

Super simple subdomain middleware for expressjs
414 stars 49 forks source link

Not working with referencing routes #56

Closed stgonzales closed 4 years ago

stgonzales commented 4 years ago

I having a problem in trying to implement express-subdomain. I can be a problem or it is not clear to me what is going on. I have my routes in a separate file and I am importing to the server file, it works fine, but when I try to use express-subdomain it's not working.

server.js

const subdomain = require('express-subdomain')
const cors = require('cors')

require('./database')

const port = process.env.PORT || 5003

const app = express()

app.use(cors())
app.use(express.json())

const routes = require('./routes')

app.use(subdomain('api',routes))

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

routes.js

const express = require('express')
const UserController = require('./controllers/UserController')
const CustomerController = require('./controllers/CustomerController')

const routes = express.Router()

//USER-ROUTES
routes.get('/twa/users', UserController.index)

routes.post('/twa/new-user', UserController.store)

routes.put('/twa/updt-user', UserController.update)

module.exports = routes;

I really need help with this. I am new with programing so, please be patient.