1.0.7 • Published 3 years ago
@opengalaxium/tinyhttp v1.0.7
tinyhttp
Light, fast, compact web framework
GitHub repo: https://github.com/OpenGalaxium/tinyhttp
npm package: https://www.npmjs.com/package/@opengalaxium/tinyhttp
Installation
npm i @opengalaxium/tinyhttp
Example usage
index.ts
import tinyhttp from '@opengalaxium/tinyhttp'
import { parser } from '@opengalaxium/tinyhttp'
import routes from './routes'
const app = new tinyhttp()
app.use(parser.json)
app.use(parser.urlencoded)
app.get('/', (req, res) => {
res.send('working!')
})
routes(app)
app.run(80, 'localhost').then((port) => {
console.log(`tinyhttp is running on port ${port}`)
})
routes.ts
import tinyhttp from 'tinyhttp'
function routes(app: tinyhttp) {
app.get('/json', (req, res) => {
res.json({ status: 'working' })
})
app.post('/post', (req, res) => {
res.send(req.body)
})
app.get('/render', (req, res) => {
res.render('index.html', { title: 'res.render example', msg: 'render' })
})
app.static('/www')
}
export default routes;