This commit is contained in:
Tommy Parnell
2022-03-10 20:55:37 -05:00
commit dd4c0b5cf5
4 changed files with 1175 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

31
index.mjs Normal file
View 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
View 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

File diff suppressed because it is too large Load Diff