cjk-readings
Version:
Web service that generates readings for chinese characters.
28 lines (22 loc) • 633 B
text/typescript
import express from 'express'
import nocache from 'nocache'
import { generatePinyin } from './generatePinyin'
export function createApp({ debug = false } = {}): express.Application {
const app = express()
app.use(nocache())
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept',
)
next()
})
app.get('/pinyin', (req, res) => {
if (debug) {
console.log('generating pinyin for:', req.query.text)
}
res.json(generatePinyin(req.query.text))
})
return app
}