💭

JWT Authentication【12Credentials】

2022/10/14に公開約700字

JWT Authentication【12Credentials】

YouTube: https://youtu.be/-YrRdV8fGiw

index.ts
import express from 'express'
import helmet from 'helmet'
import morgan from 'morgan'
import cors from 'cors'
import userRoute from './routes/user'
import postRoute from './routes/post'
import authRoute from './routes/auth'

const app = express()
const port = 4000

app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(cors({
  origin: 'http://localhost:3000',
  credentials: true
}))
app.use(helmet())
app.use(morgan('common'))

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.use('/api/users', userRoute)
app.use('/api/posts', postRoute)
app.use('/api/auth', authRoute)

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


Discussion

ログインするとコメントできます