init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
31
index.mjs
Normal file
31
index.mjs
Normal file
@@ -0,0 +1,31 @@
|
||||
import Fastify from 'fastify';
|
||||
import Prism from 'prismjs';
|
||||
import loadLanguages from 'prismjs/components/index.js';
|
||||
|
||||
loadLanguages();
|
||||
|
||||
const fastify = Fastify({
|
||||
logger: true
|
||||
})
|
||||
// Declare a route
|
||||
fastify.post('/', function (request, reply) {
|
||||
const data = request.body
|
||||
if(!data.startsWith('```')) {
|
||||
return reply.send(request.body)
|
||||
}
|
||||
const regex = data.match(/^```([a-zA-Z]*)$/m)
|
||||
const lang = regex[1]
|
||||
if(!lang) {
|
||||
return reply.send(request.body)
|
||||
}
|
||||
return Prism.highlight(data, Prism.languages[lang], lang)
|
||||
})
|
||||
|
||||
// Run the server!
|
||||
fastify.listen(process.env.PORT || 3000, function (err, address) {
|
||||
if (err) {
|
||||
fastify.log.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(`Server is now listening on ${address}`)
|
||||
})
|
||||
17
package.json
Normal file
17
package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "prismasaservice",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.mjs",
|
||||
"scripts": {
|
||||
"start": "node ./index.mjs"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"fastify": "^3.27.4",
|
||||
"fastify-cli": "^2.15.0",
|
||||
"prismjs": "^1.27.0"
|
||||
}
|
||||
}
|
||||
1126
pnpm-lock.yaml
generated
Normal file
1126
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user